

function chatframe()
{
	//var cs=null;
	/*var frd={};
	frd.id=frdmsg.id;
	frd.img=frdmsg.img;
	frd.sign=frdmsg.sign;
	frd.newinfo=frdmsg.newinfo;
	frd.msgset=frdmsg.msgset;
	frd.bgset=frdmsg.bgset;
	frd.btnset=frdmsg.btnset;
	frd.status=frdmsg.status;
	frd.qqshow=frdmsg.qqshow;
	*/
	//var usr=null;
	this.init=function(f,curid,type)
	{
	
		_createbox(f,curid,type);
		//cs=new ChatScroll(curid,f.frdid);
		//console.log("打开的fid="+f);
		_bind();
		
	}
	function _createbox(f,curid,type)
	{
		if($('#chatframe_'+type+f.frdid+'_'+curid).length>0)
		{
			return false;
		}
		f.frdname=f.frdname==""||f.frdname==undefined?f.name:f.frdname;
		
		var fimg=f.img;
		if(type=='frd')
		{
			var frdobj=usr.getaother(curid,f.frdid);
			fimg=frdobj.status==0?frdobj.imggray:f.img;
		}

		$("body").append(
		'<div class="chatframe owner_'+curid+'" id=chatframe_'+type+f.frdid+'_'+curid+'>'+
		'<div class="chatcolor"></div>'+
		'<div class="chatbg">'+
		'<div class="chatbghead"></div>'+
		'<div class="chatbgcnt">'+
		'<div class="chatbgleft"></div>'+
		'<div class="chatbgright"></div></div></div>'+
		'<div class="chatboard">'+
		'<div class="chathead">'+
		'<div class="chatheadleft">'+
		'<div class="frdmsg">'+
		'<div class="frddetail">'+
		'<div class="imghead"><img class="imghead_status" src="'+fimg+'"/><div class="frdolflag"></div></div>'+
		'<div class="detail">'+
		'<div class="frdnw">'+
		'<div class="frdname">'+f.frdname+'</div>'+
		'<div class="writing">正在输入...</div>'+
		'<div class="clear"></div>'+
		'</div>'+
		'<div class="frdnew"><img src="img/chatframe/aio_icon_qzone_16.png" title="进入QQ空间"/><font>'+f.sign+'<span>个性签名更新:&#10;<br/>'+f.sign+'&#10;<br/><a href="#">评论</a></span></font></div>'+
		'</div>'+
		'</div>'+
		'</div>'+
		'<div class="chattools">'+
		'<div class="toolsbar">'+
		'<!--<div class="audio ctools" title="开始语音通话"></div>'+
		'<div class="video ctools" title="开始视频通话"></div>'+
		'<div class="remote ctools" title="远程演示"></div>'+
		'<div class="files ctools" title="传说文件"></div>'+
		'<div class="remotectrl ctools" title="远程桌面"></div>-->'+
		'<div class="adddiscus ctools" title="创建讨论组"></div>'+
		'<div class="moreapp ctools" title="应用"></div>'+
		'</div></div></div>'+
		'<div class="chatheadright">'+
		'<div class="chatcustombutton">'+
		'<div class="chatclose" title="关闭"></div>'+
		'<div class="chatmax" title="最大化"></div>'+
		'<div class="chatmin" title="还原"></div>'+
		'<div class="chattiny" title="最小化"></div>'+
		'<div class="chatmoreset" title="窗口设置"></div>'+
		'</div>'+
		'<div class="chatheadadv"><img src=""/></div></div>'+
		'</div>'+
		'<div class="chatcontent">'+

		'<div class="chatright">'+

		'<!----------------------右侧总内容框--------------------------------------------------------------------------------------------------------------------->'+
		'<div class="chatrightcnt">'+
		'<!---右侧广告板--->'+
		'<div class="chatrightadv">'+

		'</div>'+
		'<!---右侧功能板 添加页面class可以选择chatright_content内显示的内容(page_msghistroy/page_searchmsg)-->'+
		'<div class="chatrightbox page_msghistroy">'+
		/*
		'<div class="chatright_tabbar">'+
		'<div class="chatright_tabbtn msghistroy">消息记录<div class="chattab_close" title="关闭"></div></div>'+
		'<div class="chatright_tabbtn searchmsg">搜索<div class="chattab_close" title="关闭"></div></div>'+
		'</div>'+
		'<!--功能内容板-->'+
		'<div class="chatright_content">'+
		'<!--功能页面板(消息记录)  open_msghistory_search控制开启搜索条件bar--->'+
		'<div class="chatright_contentpage chatframe_msghistroy ">'+
		'<div class="msghistroy_typebar">'+
		'<div class="msghistroy_typetab selected">全部</div>'+
		'<div class="msghistroy_typetab">图片</div>'+
		'<div class="msghistroy_typetab">文件</div>'+
		'</div>'+
		'<div class="msghistroy_board">'+
		'<div class="msghistroy_cnt">'+
	
		'</div>'+
		'</div>'+
'<div class="msghistroy_searchboard">'+
'<div class="msghistroy_searchtipbar"><div class="rstips">已搜索到40条消息记录</div> <div class="hidethis"><img src="img/MsgMgr/back_normal.png"/>返回</div></div>'+
'<!--搜索消息记录内容框-->'+
'<div class="msghistroy_searchcntboard search_result">'+
'<div class="msghistroy_searchcnt">'+
'<div class="msghistroy_pageload"></div>'+

'</div>'+
'</div>'+
'<!--搜索消息后-->'+
'<div class="msghistroy_searchcntboard search_rspage">'+
'<div class="msghistroy_cnt">'+
'<div class="msghistroy_pageload"></div>'+

'</div>'+
'</div>'+
'</div>'+
		'<div class="msghistroy_bottomtools">'+
		'<div class="msghistroy_searchbar">'+
		'<p>范围:</p>'+
		'<div class="msghistroy_range">'+
		'<select>'+
		'<option value="30">最近一个月</option>'+
		'<option value="90">最近三个月</option>'+
		'<option value="180">最近半年</option>'+
		'<option value="365">最近一年</option>'+
		'<option value="0" selected>全部</option>'+
		'</select>'+
		'</div>'+
		'<p>内容:</p>'+
		'<div class="searchmsgstr"><input name="searchmsg" class="searchinput" type="text"/><div class="delall"></div></div>'+
		'<div class="submitsearch" title="查找">确定</div>'+
		'</div>'+
		'<div class="msghistroy_bottomtoolscnt">'+
		'<div class="msghistroy_setbtn" title="设置"><div class="setico"></div>设置</div>'+
		'<div class="msghistroy_searchbtn" title="打开搜索条"></div>'+
		'<div class="msgmanagerbtn" title="打开消息管理器"></div>'+
			
	
		'<div class="msghistroy_pageindexboard normalindex">'+
		'<div class="msghistroy_gopage">'+
		'<div class="firstpage gopagebtn" title="第一页"></div>'+
		'<div class="lastpage gopagebtn" title="上页"></div>'+
		'<div class="nextpage gopagebtn disable" title="下页"></div>'+
		'<div class="thelastpage gopagebtn disable" title="最后一页"></div>'+
		'</div>'+
		'<div class="msghistroy_date">'+
		'<div class="calendarico"></div>'+
		'<p class="calendardate">2015-8-24</p>'+
		'<div class="calendarcontent"></div>'+
		'<!--日历框容器-->'+
		'<div class="calendarcontent">'+
		'<div class="calendarboard">'+
		'<div class="colorboard">'+
		'<div class="colorhead"></div>'+
		'<div class="colorbody"></div>'+
		'</div>'+
		'<div class="calendarcnt">'+
		'<div class="calendarcnthead">'+
		'<div class="datectrl">'+
		'<div class="lastyear" title="上一年"></div>'+
		'<div class="lastmonth" title="上一个月"></div>'+
		'<div class="nowdate"><span class="monthstr">八月</span><span class="yearstr">2015</span></div>'+
		'<div class="nextyear" title="没有下一年了"></div>'+
		'<div class="nextmonth" title="下一个月"></div>'+
		'</div>'+
		'<div class="datelist">'+
		'<div class="datestr">日</div>'+
		'<div class="datestr">一</div>'+
		'<div class="datestr">二</div>'+
		'<div class="datestr">三</div>'+
		'<div class="datestr">四</div>'+
		'<div class="datestr">五</div>'+
		'<div class="datestr">六</div>'+
		'</div>'+
		'<div class="clear"></div>'+
		'</div>'+
		'<div class="calendarcntbody">'+
		'<div class="calendarcntbody_load"></div>'+
		'</div>'+
		'</div>'+
		'</div>'+
		'</div><!--日历框容器结束-->'+
		
		'</div>'+
		'</div>'+
		
		'<div class="msghistroy_pageindexboard searchindex">'+
		'<div class="msghistroy_gopage">'+
		'<div class="firstpage gopagebtn" title="第一页"></div>'+
		'<div class="lastpage gopagebtn" title="上页"></div>'+
		'<div class="nextpage gopagebtn disable" title="下页"></div>'+
		'<div class="thelastpage gopagebtn disable" title="最后一页"></div>'+
		'</div>'+
		'<div class="msghistroy_date">'+
		'<div class="calendarico"></div>'+
		'<p class="calendardate">2015-11-54</p>'+
		'<!--日历框容器-->'+
		'<div class="calendarcontent">'+
		'<div class="calendarboard">'+
		'<div class="colorboard">'+
		'<div class="colorhead"></div>'+
		'<div class="colorbody"></div>'+
		'</div>'+
		'<div class="calendarcnt">'+
		'<div class="calendarcnthead">'+
		'<div class="datectrl">'+
		'<div class="lastyear" title="上一年"></div>'+
		'<div class="lastmonth" title="上一个月"></div>'+
		'<div class="nowdate"><span class="monthstr">八月</span><span class="yearstr">2015</span></div>'+
		'<div class="nextyear" title="没有下一年了"></div>'+
		'<div class="nextmonth" title="下一个月"></div>'+
		'</div>'+
		'<div class="datelist">'+
		'<div class="datestr">日</div>'+
		'<div class="datestr">一</div>'+
		'<div class="datestr">二</div>'+
		'<div class="datestr">三</div>'+
		'<div class="datestr">四</div>'+
		'<div class="datestr">五</div>'+
		'<div class="datestr">六</div>'+
		'</div>'+
		'<div class="clear"></div>'+
		'</div>'+
		'<div class="calendarcntbody">'+
		'<div class="calendarcntbody_load"></div>'+
		'</div>'+
		'</div>'+
		'</div>'+
		'</div><!--日历框容器结束-->'+
		'</div>'+
		'</div>'+

		'</div>'+
		'</div>'+
		'</div><!--功能页面板结束(消息记录)-->'+

		'<!--功能页面板(搜索)-->'+
		'<div class="chatright_contentpage chatframe_msgsearchboard">'+

		'</div><!--功能页面板结束(搜索)-->'+

		'</div><!--功能内容板结束-->'+
		*/
		'</div><!---右侧功能板结束-->'+
		
		'</div><!--------------------------------------------右侧总内容框结束--------------------------------------------------------------------------------------------->'+
		



		'</div>'+
		'<!---需要显示右边广告时 class="chatrightshow" title="显示侧边"--->'+
		'<div class="adv_hidebar chatrighthide" title="隐藏侧边"></div>'+

		'<div class="chatleft">'+
		'<div class="chatbox" id="chatbox_'+type+f.frdid+'_'+curid+'">'+
		'<div class="chatcntscroll">'+
		'<div class="totop"></div>'+
		'<div class="scrollframe">'+
		'<div class="topstep"><div class="topstepbtn"></div></div>'+
		'<div class="scrollbar"><div class="scrollblock"></div></div>'+
		'<div class="bottomstep"><div class="bottomstepbtn"></div></div>'+
		'</div>'+
		'<div class="tobottom"></div></div>'+
		'<!---内容页--->'+
		'<div class="chatcntbox">'+
		'<!---滚动内容页结束--->'+
		'<div class="chatcntpage" id="chatcntpage_'+type+f.frdid+'_'+curid+'">'+
		'<!---msg_list列表显示 / msg_bubble气泡显示--->'+
		'<div class="chatbox_msgtype '+(parseInt(usr.getpro(curid,'theme','chatmode'))>0?'msg_bubble':'msg_list')+'" id="">'+
'<!--顶部加载历史消息提示 sh_link sh_load sh_fail sh_end sh_ended表示提示状态-->'+
'<div class="showhistorylink sh_link">'+
'<div class="time_icon"></div><a href="javascript:;" onClick="" class="showhistorylink_a">查看历史消息</a>'+
'<div class="loadingicon"></div>'+
'<div class="failtips"><div class="fail_icon"></div>加载失败</div>'+
'<p class="endtips">更多消息请在消息记录中查阅</p><a href="javascript:;" class="openhibox">,打开消息记录</a>'+
'</div>'+

		
		'</div><!--气泡或列表展示框--->'+
		'</div><!---滚动内容页结束--->'+

		'<!---聊天框底部新信息提示--->'+
		'<div class="chatbottomnewtipsbar">'+
		'<div class="chatnewtips_who"><img src=""/></div>'+
		'<div class="chatnewtips_cnt"></div>'+
		'</div><!---聊天框底部新信息提示--->'+

		'</div><!---内容页结束--->'+
		'<div class="clear"></div></div>'+
		'<div class="chatinput">'+
		'<div class="midtoolbar">'+
		'<div class="midfontset">'+
		'<div class="bubble_type">'+
		'<div class="switch_font_type">'+
		'<div class="tobubble">气泡模式</div>'+
		'<div class="tolist">文本模式</div>'+
		'<div class="clear"></div>'+
		'</div><div class="bubble_theme">选择气泡</div>'+
		'<div class="font_size">'+
		'字体大小'+
		'<select>'+
		'<option value ="12">12</option>'+
		'<option value ="13">13</option>'+
		'<option value="14">14</option>'+
		'<option value="15">15</option>'+
		'<option value="16">16</option>'+
		'<option value="17">17</option>'+
		'<option value="18">18</option>'+
		'</select>'+
		'</div>'+
		'<div class="font_family" title="默认字体">默认字体</div>'+
		'<div class="clear"></div>'+
		'</div>'+
		'<div class="list_type">'+
		'<div class="switch_font_type">'+
		'<div class="tobubble">气泡模式</div>'+
		'<div class="tolist">文本模式</div>'+
		'</div>'+
		'<div class="sys_color_board" title="颜色"></div>'+
		'<div class="font_underline" title="下划线"></div>'+
		'<div class="font_incline" title="倾斜"></div>'+
		'<div class="font_bold" title="加粗"></div>'+
		'<div class="font_size">'+
		'<select>'+
		'<option value ="12">12</option>'+
		  '<option value ="13">13</option>'+
		  '<option value="14">14</option>'+
		  '<option value="15">15</option>'+
		  '<option value="16">16</option>'+
		  '<option value="17">17</option>'+
		  '<option value="18">18</option>'+
		  '<option value="19">19</option>'+
		  '<option value="20">20</option>'+
		  '<option value="21">21</option>'+
		  '<option value="22">22</option>'+
		'</select>'+
		'</div>'+
		'<div class="font_family">'+
		'<select>'+
		  '<option value ="微软雅黑">微软雅黑</option>'+
		  '<option value ="宋体">宋体</option>'+
		  '<option value ="仿宋">仿宋</option>'+
		  '<option value ="新宋体">新宋体</option>'+
		  '<option value ="黑体">黑体</option>'+
		  '<option value ="楷体">楷体</option>'+ 
		'</select>'+
		'</div>'+
		'<div class="font_type">'+
		'<div class="normal_font" title="系统字体"></div>'+
		'<div class="color_font" title="个性字体"></div>'+
		'</div>'+
		'<div class="clear"></div></div></div>'+
		'<div class="midtoolcnt" id="midtoolcnt_'+type+f.frdid+'_'+curid+'">'+
		'<div class="chatfontset font left" title="字体选择工具栏"></div>'+
		'<div class="face left" title="选择表情"></div>'+
		'<div class="richface left" title="VIP魔法表情/超级表情/涂鸦表情/宠物炫"></div>'+
		'<div class="twitter left" title="向好友发送窗口抖动"></div>'+
		'<div class="inputassist left" title="多功能辅助输入"></div>'+
		'<div class="sendpic left" title="发送图片"><input type="file" class="picfile" name="picfile" id="picfile_'+type+f.frdid+'_'+curid+'"/></div>'+
		'<div class="cut left" title="屏幕截图 Ctrl + Alt + A"></div>'+
		'<div class="msghis" title="显示消息记录">消息记录</div>'+
		'<div class="clear"></div>'+
		'</div></div>'+
		'<div class="inputbox" id="inputbox_'+type+f.frdid+'_'+curid+'">'+
		'<div class="inputscroll">'+
		'<div class="inputtopstep"><div class="inputtopstepbtn"></div></div>'+
		'<div class="inputscrollbar"><div class="inputscrollblock"></div></div>'+
		'<div class="inputbottomstep"><div class="inputbottomstepbtn"></div></div>'+
		'</div><div class="inputboxcnt"><div class="inputboxcntpage" contenteditable="true"></div></div></div>'+
		'<div class="bottombar">'+
		'<div class="bottombutton">'+
		'<div class="chatsend">'+
		'<div class="sendbtn" id="sendbtn_'+type+f.frdid+'_'+curid+'" title="按Enter键发送消息，按Ctrl+Enter键换行">发送(S)</div>'+
		'<div class="split"><img src="img/chatframe/ButtomBtn_SplitLine.png"/></div>'+
		'<div class="sendset"><img src="img/chatframe/buttomctrl_arrow.png"/></div></div>'+
		'<div class="chatbigclose">关闭(C)</div></div>'+
		'<div class="bottomadv"><a href="#" title="大学时光太闲？来赶集网找工作吧！！哈哈哈哈哈哈哈哈">大学时光太闲？来赶集网找工作吧！！哈哈哈哈哈哈哈哈</a></div></div>'+
		'<div class="clear"></div></div></div></div>'+
		'<div class="clear"></div>'+
		'</div></div></div>');

		bottombar.add(type+f.frdid,curid,f.frdname);
		
		//设置聊天框样式
		usr.getpro(curid,'setting','chatframe_showmyskin');
		//首先查看是否设置了只显示自己的主题
		if(parseInt(usr.getpro(curid,'setting','chatframe_showmyskin'))==0)
		{
			$.ajax({
				url:'action/settheme.php',
				data:'u='+f.frdid+'&&m=get',
				dataType:'json',
				method:'POST',
				success:function(m)
				{
					if(m!=false)
					{
						//console.log(m);
						//更新好友气泡到全局数组中
						if(usr.set2pro(curid,'frd','id',f.frdid,'bubble',{'img':m.bubble_imgshow,'bg':m.bubble_bgimg}))//2015/11/2还需要设置添加信息到聊天框时读取好友和自己设置的气泡--------------------------------------
						{
							//console.log(usr.get4pro(curid,'frd','id',f.frdid,'bubble'));
						}

						//获取好友主题后，查看他是否设置了显示给他人查看，如果没有设置，则显示自己的主题
						if(m.isshow==1)
						{
							//设置默认背景和按钮css
							$("#chatframe_"+type+f.frdid+"_"+curid+" .chatsend").css("background",m.bgcolor);
							$("#chatframe_"+type+f.frdid+"_"+curid+" .chatbigclose").css("background",m.bgcolor);
							
							$("#chatframe_"+type+f.frdid+"_"+curid+">.chatcolor").css("background",m.bgcolor);
							m.bgimg.length>0?$("#chatframe_"+type+f.frdid+"_"+curid+">.chatcolor").css("background",'url('+m.bgimg+')').css('background-size','cover'):'';
							
						}
						else
						{
							var im=usr.getuser(curid);
							//设置默认背景和按钮css
							$("#chatframe_"+type+f.frdid+"_"+curid+" .chatsend").css("background",im.theme.bgcolor);
							$("#chatframe_"+type+f.frdid+"_"+curid+" .chatbigclose").css("background",im.theme.bgcolor);
							if(im.theme.bgimg.length>0)
							{
								$("#chatframe_"+type+f.frdid+"_"+curid+">.chatcolor").css("background",'url('+im.theme.bgimg+')').css('background-size','cover');
							}
							else
							{
								$("#chatframe_"+type+f.frdid+"_"+curid+">.chatcolor").css("background",im.theme.bgcolor);
							}
						}
						
					}
				}
		
			});
		}
		else
		{
			var im=usr.getuser(curid);
			//设置默认背景和按钮css
			$("#chatframe_"+type+f.frdid+"_"+curid+" .chatsend").css("background",im.theme.bgcolor);
			$("#chatframe_"+type+f.frdid+"_"+curid+" .chatbigclose").css("background",im.theme.bgcolor);
			if(im.theme.bgimg.length>0)
			{
				$("#chatframe_"+type+f.frdid+"_"+curid+">.chatcolor").css("background",'url('+im.theme.bgimg+')').css('background-size','cover');
			}
			else
			{
				$("#chatframe_"+type+f.frdid+"_"+curid+">.chatcolor").css("background",im.theme.bgcolor);
			}
		}
		
		
		//$("#chatcntpage_"+id)[0].scrollTop=$("#chatcntpage_"+id)[0].scrollHeight;
		//ajax获取用户主题
		msgcenter.show2box(f.frdid,curid,type);
		$("#chatframe_"+type+f.frdid+"_"+curid).show('fast');
		/*if($('#msgboxlist_'+f.frdid+'_'+curid).length>0)
		{
			$('#msgboxlist_'+f.frdid+'_'+curid).trigger('click');
		}*/
	}
	function _bind()
	{
		$(".chatframe").click(function()
		{
			if($(this).css("display")=='none')
			{
				$(this).show('fast');
			}
			var chatid=$(this).attr("id");

			//置顶当前界面
			toper.set(chatid);
			//$("#"+chatid.replace('chatframe','bar')).trigger('click');
			$(".tinycnt").attr('class','tinycnt tinynone');
			$("#"+chatid.replace('chatframe','bar')).attr('class',"tinycnt tinyshow");
			//$(this).find('.inputboxcntpage')[0].focus();

		}).dblclick(function()
		{
			var chatid=$(this).attr("id");
			
			//置顶当前界面
			toper.set(chatid);
			//$("#"+chatid.replace('chatframe','bar')).trigger('click');
			$(".tinycnt").attr('class','tinycnt tinynone');
			$("#"+chatid.replace('chatframe','bar')).attr('class',"tinycnt tinyshow");
			//$(this).find('.inputboxcntpage')[0].focus();
		});
		
		$('.chatbox').mouseover(function()
		{
			var now=$(this).attr('id');
			var reg=/chatbox_(\w+)_(\d+)/;
			var cid=reg.exec(now);//cid[0]=chatframe_x_y cid[1]=x cid[2]=y
			//更新当前用户id和好友id
			var uid=parseInt(cid[2]);
			var fid=cid[1];
			
			if(setScroll(uid,fid,'chatbox','chatcntpage','chatcntscroll','scrollframe','scrollbar','scrollblock',12)!=false)
			{
				$(this).find('.scrollblock').css('display','block');
			}
			



		}).mouseout(function()
		{
			window.onmousewheel=document.onmousewheel=null;
			$(this).find('.scrollblock').css('display','none');
		});




		







		//设置拖拽
		drag($(".chatframe"));

		$(".inputbox").mouseover(function()
		{
			var now=$(this).attr('id');
			var reg=/inputbox_(\w+)_(\d+)/;
			var cid=reg.exec(now);//cid[0]=chatframe_x_y cid[1]=x cid[2]=y
			//更新当前用户id和好友id
			var uid=parseInt(cid[2]);
			var fid=cid[1];

			
			/*if(setScroll(uid,fid,'inputbox','inputboxcntpage','inputscroll','inputscroll','inputscrollbar','inputscrollblock',12)!=false)
			{
				$(this).find('.inputscrollblock').css('display','block');
			}*/
			$(this).find('.inputboxcntpage')[0].focus();
			
		}).mouseout(function()
		{
			$(this).find('.inputscrollblock').css('display','none');
		});

		$('.inputboxcntpage').focus(function()
		{
			/*console.log('onchange');
			var offset=$(this).parent('.inputboxcnt').parent('.inputbox')[0].clientHeight-$(this)[0].offsetHeight;
			if(offset<0)
			{
				$(this).css('top',-offset+'px');
			}
			*/
			//$(this).parent('.inputboxcnt').parent('.inputbox').trigger('mouseover');
		}).keyup(function()
		{
			//console.log('val='+$(this).html());
			//console.log($(this).html().split("<br>").length-1);
		}).keydown(function(e)
		{
			if(e.keyCode==13)
			{

			}
		});
		
		


		$(".chatclose").click(function()
		{
			bottombar.remove(toper.fid(),toper.id());
			$(this).parent(".chatcustombutton").parent(".chatheadright").parent(".chathead").parent(".chatboard").parent(".chatframe").remove();
			
		});
		$(".chattiny").click(function()
		{
			$(this).parent(".chatcustombutton").parent(".chatheadright").parent(".chathead").parent(".chatboard").parent(".chatframe").hide("fast");
		});
		
		$('.chatmax').click(function()
		{
			var cf=$(this).parents('.chatframe');
			var inputheight=cf.find(".chatcontent>.chatleft>.chatinput")[0].offsetHeight;
			//判断当前框的高度
			var cheight=0;
			if (window.innerHeight)
			{
				cheight = window.innerHeight-32;//减去底部的bar
			}
			else if ((document.body) && (document.body.clientHeight))
			{
				cheight = document.body.clientHeight-32;//减去底部的bar
			}
			cf.css("top","0").css("left","0").css("height",cheight+"px");

			//获取左侧主内容区高度
			var leftheight=cf.find(".chatcontent>.chatleft")[0].offsetHeight;
			
			//判断内容区高度
			var cntheight=leftheight-inputheight-2;
			cf.find(".chatcontent>.chatleft>.chatbox").css("height",cntheight+"px");

			cf.addClass('chatbig');
		});
		$('.chatmin').click(function()
		{
			$(this).parents(".chatframe").css("top","10%").css("left","20%").css("height","0");
			if($(this).parents(".chathead").siblings(".chatcontent").find(".chatleft>.chatinput")[0].offsetHeight<168)
			{
				//console.log("大box"+$(this).parent(".chatcustombutton").parent(".chatheadright").parent(".chathead").siblings(".chatcontent").find(".chatleft>.chatinput")[0].offsetHeight);
				$(this).parents(".chatboard").find(".chatcontent>.chatleft>.chatbox").css("height","288px");
			}
			else
			{
				$(this).parents(".chatboard").find(".chatcontent>.chatleft>.chatbox").css("height","255px");
			}
			$(this).parents('.chatframe').removeClass('chatbig');
		});
		

		$(".chatfontset").click(function(e)
		{
			var ci=$(this).parent(".midtoolcnt").parent(".midtoolbar").parent(".chatinput");

			if($(this).attr("class").indexOf("fontdown")>=0)
			{
				
				ci.find(".midfontset").css("display","none");
				//调节高度
				var lh=ci.parent(".chatleft")[0].clientHeight;
				var inh=ci[0].offsetHeight;
				var boxh=lh-inh-2+33;
				//$(this).parent(".midtoolcnt").parent(".midtoolbar").parent(".chatinput").css("height",(inh+2)+"px");
				ci.siblings(".chatbox").css("height",boxh+"px");

				tobottom(toper.fid(),toper.id());
				///cs.resize(toper.id(),toper.fid());
				setScroll(toper.id(),toper.fid(),'chatbox','chatcntpage','chatcntscroll','scrollframe','scrollbar','scrollblock',12);
				$(this).attr("class","chatfontset font left");
				
				//阻止事件触发多次
				e.stopImmediatePropagation();
			}
			else
			{
				
				ci.find(".midfontset").css("display","block");
				//调节高度
				var lh=ci.parent(".chatleft")[0].clientHeight;
				var inh=ci[0].offsetHeight;
				var boxh=lh-inh-2;
				//$(this).parent(".midtoolcnt").parent(".midtoolbar").parent(".chatinput").css("height",(inh-2)+"px");
				ci.siblings(".chatbox").css("height",boxh+"px");

				//根据内容框气泡或文字来显示气泡模式还是文字模式
				
				if(ci.siblings(".chatbox").find(".chatcntbox>.chatcntpage>.chatbox_msgtype").attr("class")=="chatbox_msgtype msg_bubble")
				{
					ci.find(".midfontset>.bubble_type").css("display","block");
					ci.find(".midfontset>.list_type").css("display","none");
				}
				else
				{
					ci.find(".midfontset>.bubble_type").css("display","none");
					ci.find(".midfontset>.list_type").css("display","block");
				}
		
				tobottom(toper.fid(),toper.id());
				//cs.resize(toper.id(),toper.fid());
				setScroll(toper.id(),toper.fid(),'chatbox','chatcntpage','chatcntscroll','scrollframe','scrollbar','scrollblock',12);
				$(this).attr("class","chatfontset fontdown left");
				
				//阻止事件触发多次
				e.stopImmediatePropagation();
			}
			
			
			//绑定事件
			bind();
			
		});


		$(".chatright").mouseover(function(e)
		{
			var h=$(this).siblings(".chatleft").find(".chatbox")[0].clientHeight;
			//console.log("h="+h);
			//console.log($(this)[0].offsetHeight);
			$(this).siblings(".adv_hidebar").css("height",h+"px").css("display","block");
			//阻止事件触发多次
			e.stopImmediatePropagation();
			bind();
		});
		
		$('.showhistorylink_a').click(function(e)
		{
			var cid=/chatframe_([a-zA-Z]+)(\d+)_(\d+)/.exec($(this).parents('.chatframe').attr('id'));
			var type=cid[1];
			var fid=cid[2];
			var uid=cid[3];

			var link=$(this).parents('.showhistorylink');
			if(link.siblings('.sendtime_cnt').length<=0)
			{
				addhistory2chatbox(link,uid,fid,'frd',0,3);
			}
			else
			{
				var msgcnt=link.parents(".chatbox_msgtype").find(".msgcnt");
				addhistory2chatbox(link,uid,fid,'frd',msgcnt.eq(0).attr('cmid'),25);
			}
			e.stopImmediatePropagation();
		});


		$('.openhibox').click(function(e)
		{
			var hisbtn=$(this).parents('.chatframe').find('.midtoolcnt .msghis');
			if(!hisbtn.hasClass('clicked'))
			{
				hisbtn.trigger('click');
			}
			$(this).parents('.showhistorylink').attr('class','showhistorylink sh_ended cantload');
			
			e.stopImmediatePropagation();
		});
		
		$('.msghis').click(function(e)
		{
			var cf=$(this).parents('.chatframe');
			var cnt=cf.find('.chatrightbox');
			if(cf.hasClass('open_chatright'))
			{
				//关闭消息记录
				$(this).attr('title','显示消息记录').removeClass('clicked');
				var linkbtn=$(this).parents('.chatframe').find('.showhistorylink');
				if(linkbtn.hasClass('sh_ended')||linkbtn.hasClass('sh_end'))
				{
					$(this).parents('.chatframe').find('.showhistorylink').attr('class','showhistorylink sh_end cantload');
				}
				if(cnt.find('.chatright_contentpage').length>1&&cnt.find('.chatright_tabbtn').length>1)
				{
					cnt.find('.chatright_tabbar .msghistroy').remove();
					cnt.find('.chatframe_msghistroy').remove();
					var pagename=cnt.find('.chatright_tabbtn').eq(0).attr('class').replace('chatright_tabbtn ','');
					cnt.attr('class','chatrightbox page_'+pagename);
				}
				else
				{
					cnt.html('');
					cf.removeClass('open_chatright').removeClass('temphide');
					cf.find('.chatrightbox').attr('class','chatrightbox');
				}
			}
			else
			{
				var linkbtn=$(this).parents('.chatframe').find('.showhistorylink');
				if(linkbtn.hasClass('sh_ended')||linkbtn.hasClass('sh_end'))
				{
					$(this).parents('.chatframe').find('.showhistorylink').attr('class','showhistorylink sh_ended cantload');
				}
				//显示消息记录
				if(cnt.html().length<=0)
				{
					cnt.html(
					'<div class="chatright_tabbar">'+
					'<div class="chatright_tabbtn msghistroy">消息记录<div class="chattab_close" title="关闭"></div></div>'+
					'</div>'+
					'<!--功能内容板-->'+
					'<div class="chatright_content">'+
					'<!--功能页面板(消息记录)  open_msghistory_search控制开启搜索条件bar--->'+
					'<div class="chatright_contentpage chatframe_msghistroy ">'+
					'<div class="msghistroy_typebar">'+
					'<div class="msghistroy_typetab selected">全部</div>'+
					'<div class="msghistroy_typetab">图片</div>'+
					'<div class="msghistroy_typetab">文件</div>'+
					'</div>'+
					'<div class="msghistroy_board">'+
					'<div class="msghistroy_cnt">'+
					'<div class="msghistroy_pageload"></div>'+
					'</div>'+
					'</div>'+
					'<div class="msghistroy_searchboard">'+
					'<div class="msghistroy_searchtipbar"><div class="rstips">已搜索到40条消息记录</div> <div class="hidethis"><img src="img/MsgMgr/back_normal.png"/>返回</div></div>'+
					'<!--搜索消息记录内容框-->'+
					'<div class="msghistroy_searchcntboard search_result">'+
					'<div class="msghistroy_searchcnt">'+
					'<div class="msghistroy_pageload"></div>'+

					'</div>'+
					'</div>'+
					'<!--搜索消息后-->'+
					'<div class="msghistroy_searchcntboard search_rspage">'+
					'<div class="msghistroy_cnt">'+
					'<div class="msghistroy_pageload"></div>'+

					'</div>'+
					'</div>'+
					'</div>'+
					'<div class="msghistroy_bottomtools">'+
					'<div class="msghistroy_searchbar">'+
					'<p>范围:</p>'+
					'<div class="msghistroy_range">'+
					'<select>'+
					'<option value="30">最近一个月</option>'+
					'<option value="90">最近三个月</option>'+
					'<option value="180">最近半年</option>'+
					'<option value="365">最近一年</option>'+
					'<option value="0" selected>全部</option>'+
					'</select>'+
					'</div>'+
					'<p>内容:</p>'+
					'<div class="searchmsgstr"><input name="searchmsg" class="searchinput" type="text"/><div class="delall"></div></div>'+
					'<div class="submitsearch" title="查找">确定</div>'+
					'</div>'+
					'<div class="msghistroy_bottomtoolscnt">'+
					'<div class="msghistroy_setbtn" title="设置"><div class="setico"></div>设置</div>'+
					'<div class="msghistroy_searchbtn" title="打开搜索条"></div>'+
					'<div class="msgmanagerbtn" title="打开消息管理器"></div>'+


					'<div class="msghistroy_pageindexboard normalindex">'+
					'<div class="msghistroy_gopage">'+
					'<div class="firstpage gopagebtn" title="第一页"></div>'+
					'<div class="lastpage gopagebtn" title="上页"></div>'+
					'<div class="nextpage gopagebtn disable" title="下页"></div>'+
					'<div class="thelastpage gopagebtn disable" title="最后一页"></div>'+
					'</div>'+
					'<div class="msghistroy_date">'+
					'<div class="calendarico"></div>'+
					'<p class="calendardate">2015-8-24</p>'+
					'<div class="calendarcontent"></div>'+
					'<!--日历框容器-->'+
					'<div class="calendarcontent">'+
					'<div class="calendarboard">'+
					'<div class="colorboard">'+
					'<div class="colorhead"></div>'+
					'<div class="colorbody"></div>'+
					'</div>'+
					'<div class="calendarcnt">'+
					'<div class="calendarcnthead">'+
					'<div class="datectrl">'+
					'<div class="lastyear" title="上一年"></div>'+
					'<div class="lastmonth" title="上一个月"></div>'+
					'<div class="nowdate"><span class="monthstr">八月</span><span class="yearstr">2015</span></div>'+
					'<div class="nextyear" title="没有下一年了"></div>'+
					'<div class="nextmonth" title="下一个月"></div>'+
					'</div>'+
					'<div class="datelist">'+
					'<div class="datestr">日</div>'+
					'<div class="datestr">一</div>'+
					'<div class="datestr">二</div>'+
					'<div class="datestr">三</div>'+
					'<div class="datestr">四</div>'+
					'<div class="datestr">五</div>'+
					'<div class="datestr">六</div>'+
					'</div>'+
					'<div class="clear"></div>'+
					'</div>'+
					'<div class="calendarcntbody">'+
					'<div class="calendarcntbody_load"></div>'+
					'</div>'+
					'</div>'+
					'</div>'+
					'</div><!--日历框容器结束-->'+

					'</div>'+
					'</div>'+

					'<div class="msghistroy_pageindexboard searchindex">'+
					'<div class="msghistroy_gopage">'+
					'<div class="firstpage gopagebtn" title="第一页"></div>'+
					'<div class="lastpage gopagebtn" title="上页"></div>'+
					'<div class="nextpage gopagebtn disable" title="下页"></div>'+
					'<div class="thelastpage gopagebtn disable" title="最后一页"></div>'+
					'</div>'+
					'<div class="msghistroy_date">'+
					'<div class="calendarico"></div>'+
					'<p class="calendardate">2015-11-54</p>'+
					'<!--日历框容器-->'+
					'<div class="calendarcontent">'+

					'</div><!--日历框容器结束-->'+
					'</div>'+
					'</div>'+

					'</div>'+
					'</div>'+
					'</div><!--功能页面板结束(消息记录)-->'+

					'</div><!--功能内容板结束-->'
					);
				}
				else
				{
					cnt.find('.chatright_tabbar').append('<div class="chatright_tabbtn msghistroy">消息记录<div class="chattab_close" title="关闭"></div></div>');
					cnt.find('.chatright_content').append(
					'<!--功能页面板(消息记录)  open_msghistory_search控制开启搜索条件bar--->'+
					'<div class="chatright_contentpage chatframe_msghistroy ">'+
					'<div class="msghistroy_typebar">'+
					'<div class="msghistroy_typetab selected">全部</div>'+
					'<div class="msghistroy_typetab">图片</div>'+
					'<div class="msghistroy_typetab">文件</div>'+
					'</div>'+
					'<div class="msghistroy_board">'+
					'<div class="msghistroy_cnt">'+
					'<div class="msghistroy_pageload"></div>'+
					'</div>'+
					'</div>'+
					'<div class="msghistroy_searchboard">'+
					'<div class="msghistroy_searchtipbar"><div class="rstips">已搜索到40条消息记录</div> <div class="hidethis"><img src="img/MsgMgr/back_normal.png"/>返回</div></div>'+
					'<!--搜索消息记录内容框-->'+
					'<div class="msghistroy_searchcntboard search_result">'+
					'<div class="msghistroy_searchcnt">'+
					'<div class="msghistroy_pageload"></div>'+

					'</div>'+
					'</div>'+
					'<!--搜索消息后-->'+
					'<div class="msghistroy_searchcntboard search_rspage">'+
					'<div class="msghistroy_cnt">'+
					'<div class="msghistroy_pageload"></div>'+

					'</div>'+
					'</div>'+
					'</div>'+
					'<div class="msghistroy_bottomtools">'+
					'<div class="msghistroy_searchbar">'+
					'<p>范围:</p>'+
					'<div class="msghistroy_range">'+
					'<select>'+
					'<option value="30">最近一个月</option>'+
					'<option value="90">最近三个月</option>'+
					'<option value="180">最近半年</option>'+
					'<option value="365">最近一年</option>'+
					'<option value="0" selected>全部</option>'+
					'</select>'+
					'</div>'+
					'<p>内容:</p>'+
					'<div class="searchmsgstr"><input name="searchmsg" class="searchinput" type="text"/><div class="delall"></div></div>'+
					'<div class="submitsearch" title="查找">确定</div>'+
					'</div>'+
					'<div class="msghistroy_bottomtoolscnt">'+
					'<div class="msghistroy_setbtn" title="设置"><div class="setico"></div>设置</div>'+
					'<div class="msghistroy_searchbtn" title="打开搜索条"></div>'+
					'<div class="msgmanagerbtn" title="打开消息管理器"></div>'+


					'<div class="msghistroy_pageindexboard normalindex">'+
					'<div class="msghistroy_gopage">'+
					'<div class="firstpage gopagebtn" title="第一页"></div>'+
					'<div class="lastpage gopagebtn" title="上页"></div>'+
					'<div class="nextpage gopagebtn disable" title="下页"></div>'+
					'<div class="thelastpage gopagebtn disable" title="最后一页"></div>'+
					'</div>'+
					'<div class="msghistroy_date">'+
					'<div class="calendarico"></div>'+
					'<p class="calendardate">2015-8-24</p>'+
					'<div class="calendarcontent"></div>'+
					'<!--日历框容器-->'+
					'<div class="calendarcontent">'+
					'<div class="calendarboard">'+
					'<div class="colorboard">'+
					'<div class="colorhead"></div>'+
					'<div class="colorbody"></div>'+
					'</div>'+
					'<div class="calendarcnt">'+
					'<div class="calendarcnthead">'+
					'<div class="datectrl">'+
					'<div class="lastyear" title="上一年"></div>'+
					'<div class="lastmonth" title="上一个月"></div>'+
					'<div class="nowdate"><span class="monthstr">八月</span><span class="yearstr">2015</span></div>'+
					'<div class="nextyear" title="没有下一年了"></div>'+
					'<div class="nextmonth" title="下一个月"></div>'+
					'</div>'+
					'<div class="datelist">'+
					'<div class="datestr">日</div>'+
					'<div class="datestr">一</div>'+
					'<div class="datestr">二</div>'+
					'<div class="datestr">三</div>'+
					'<div class="datestr">四</div>'+
					'<div class="datestr">五</div>'+
					'<div class="datestr">六</div>'+
					'</div>'+
					'<div class="clear"></div>'+
					'</div>'+
					'<div class="calendarcntbody">'+
					'<div class="calendarcntbody_load"></div>'+
					'</div>'+
					'</div>'+
					'</div>'+
					'</div><!--日历框容器结束-->'+

					'</div>'+
					'</div>'+

					'<div class="msghistroy_pageindexboard searchindex">'+
					'<div class="msghistroy_gopage">'+
					'<div class="firstpage gopagebtn" title="第一页"></div>'+
					'<div class="lastpage gopagebtn" title="上页"></div>'+
					'<div class="nextpage gopagebtn disable" title="下页"></div>'+
					'<div class="thelastpage gopagebtn disable" title="最后一页"></div>'+
					'</div>'+
					'<div class="msghistroy_date">'+
					'<div class="calendarico"></div>'+
					'<p class="calendardate">2015-11-54</p>'+
					'<!--日历框容器-->'+
					'<div class="calendarcontent">'+

					'</div><!--日历框容器结束-->'+
					'</div>'+
					'</div>'+

					'</div>'+
					'</div>'+
					'</div><!--功能页面板结束(消息记录)-->'	
					);
				}
				cf.addClass('open_chatright').removeClass('temphide');
				cf.find('.chatrightbox').attr('class','chatrightbox page_msghistroy');
				$(this).attr('title','隐藏消息记录').addClass('clicked');
				//cnt.append('<div class="msghistroy_pageload"></div>');
				
				var cid=cf.attr('id');
				cid=/chatframe_([a-zA-Z]+)(\d+)_(\d+)/.exec(cid);
				var type=cid[1];
				var fid=cid[2];
				var uid=cid[3];
				sethistorybox(uid,fid,type,'normalindex');
			}
			e.stopImmediatePropagation();
		});
		
		//聊天框新消息提示bar，点击到底部查看
		$('.chatbottomnewtipsbar').click(function(e)
		{
			var cid=/chatframe_([a-zA-Z]+)(\d+)_(\d+)/.exec($(this).parents('.chatframe').attr('id'));
			var type=cid[1];
			var fid=cid[2];
			var uid=cid[3];
			tobottom(type+fid,uid);
			$(this).hide();
			e.stopImmediatePropagation();
		});
	




		$(".sendbtn").click(function(e)
		{
			
			var id=$(this).attr("id").replace("sendbtn","");
			

			var now=$(this).attr('id');
			var reg=/sendbtn_([a-zA-z]+)(\d+)_(\d+)/;
			var cid=reg.exec(now);//cid[0]=chatframe_x_y cid[1]=x cid[2]=y
			//更新当前用户id和好友id
			var uid=parseInt(cid[3]);
			var fid=cid[1]+cid[2];
			var ftype=cid[1];
			var foid=cid[2];
			
			if(fid.indexOf('last')>=0)
			{
				console.log('参数出错,fid含有last:'+fid);
				return;
			}
			//如果是离线状态，则返回
			if(usr.getuser(uid)==false||parseInt(usr.getpro(uid,'status'))<=0)
			{
				console.log(uid+'已离线，禁止发送消息');
				//阻止事件触发多次
				e.stopImmediatePropagation();
				return false;
			}

			var str=$("#inputbox"+id+" .inputboxcntpage").html();
			if($.trim(str).replace(/[\r\n]/g,"")!="")
			{	
				
				//发送消息
				sendmsg(uid,foid,ftype,'text',str,function(msgs)
				{
					var msg=msgs.msg;
					var cnt=msgs.cnt;
					if(msg.indexOf("ok:time=")>=0)
					{
						//console.log(msg);
						//--------------------------------------------------------------------------------------------------------
						msg=msg.replace("ok:time=","").split(';');
						
						msgcenter.add2box(msg[1],'me',fid,uid,'text',cnt,msg[0]);

						//console.log(msg[1]+','+msg[0]);
						$("#chatframe_"+fid+"_"+uid+" .chatbottomnewtipsbar").css('display','none');
						tobottom(fid,uid);
						$("#inputbox"+id+" .inputboxcntpage").html("");
						
						//添加到最近联系列表
						setlast2main(uid,'frd',foid,1,str,msg[0],'self');
					}
					else
					{
						console.log("发送失败"+msg);
					}
					

				});	
			}
			//阻止事件触发多次
			e.stopImmediatePropagation();
			//bind();
		});


		

		//发送抖动
		$(".twitter").click(function(e)
		{
			var now=$(this).parent('.midtoolcnt').attr('id');
			var reg=/midtoolcnt_([a-zA-z]+)(\d+)_(\d+)/;
			var cid=reg.exec(now);//cid[0]=chatframe_x_y cid[1]=x cid[2]=y
			//更新当前用户id和好友id
			var uid=parseInt(cid[3]);
			var fid=cid[1]+cid[2];
			var ftype=cid[1];
			var foid=cid[2];

			go(foid,fid,uid);
			//阻止事件触发多次
			e.stopImmediatePropagation();
		});

		//选择图片
		$(".picfile").change(function(e)
		{
			var now=$(this).attr('id');
				var reg=/picfile_([a-zA-z]+)(\d+)_(\d+)/;
				var cid=reg.exec(now);//cid[0]=chatframe_x_y cid[1]=x cid[2]=y
				//更新当前用户id和好友id
				var uid=parseInt(cid[3]);
				var fid=cid[1]+cid[2];
				var ftype=cid[1];
				var foid=cid[2];

			//console.log($(this).val());
			//在输入框预览这个图片
			preview(e.target,uid,foid,ftype);
			//阻止事件触发多次
			e.stopImmediatePropagation();
		});

		
		//
		_chatrightbind();
	}
	
	//选择图片后预览图片方法
	var preview=function(obj,uid,fid,ftype)
	{
		var d=new Date();
		var name=getrand(6);
		var id="imgview_"+d.getTime()+name;
		//console.log(obj.files[0]);
		if(obj.files&&obj.files[0])
		{
			//如果不是图片格式，返回并提示
			if(!/image\/\w+/.test(obj.files[0].type))
			{
				alert("您选择的不是图片噢");
				return false;
			}
			var filename=obj.files[0].name.split('.');
			var format=filename[filename.length-1].toLowerCase();
			//如果文件大小大于500k 则先上传
			if(obj.files[0].size>=1024*1024)
			{
				

				//加入到对话框中再上传
				 var date=new Date();
				 var month=date.getMonth()>10?date.getMonth()+1:0+""+parseInt(date.getMonth()+1);
				 var day=date.getDate()>10?date.getDate()+1:0+""+date.getDate();
				 var H=date.getHours()>10?date.getHours()+1:0+""+date.getHours();
				 var M=date.getMinutes()>10?date.getMinutes()+1:0+""+date.getMinutes();
				 var S=date.getSeconds()>10?date.getSeconds()+1:0+""+date.getSeconds();
				 var sendtime=date.getFullYear()+"/"+month+"/"+day+","+H+":"+M+":"+S;
				 //console.log("callback uid="+uid+" fid="+fid+" ftype="+ftype+" sendtime="+sendtime);
				 var k=[];
				 k.push(id);
				 k.push(obj.files[0]);
				 msgcenter.add2box('me',ftype+fid,uid,'pic',k,sendtime);

				//上传
				sendmsg(uid,fid,ftype,'pic',obj,function(msg)
				{
					
					//上传成功后加入到对话框中
					/* var date=new Date();
					 var month=date.getMonth()>10?date.getMonth()+1:0+""+parseInt(date.getMonth()+1);
					 var day=date.getDate()>10?date.getDate()+1:0+""+date.getDate();
					 var H=date.getHours()>10?date.getHours()+1:0+""+date.getHours();
					 var M=date.getMinutes()>10?date.getMinutes()+1:0+""+date.getMinutes();
					 var S=date.getSeconds()>10?date.getSeconds()+1:0+""+date.getSeconds();
					 var sendtime=date.getFullYear()+"/"+month+"/"+day+","+H+":"+M+":"+S;
					 console.log("callback uid="+uid+" fid="+fid+" ftype="+ftype+" sendtime="+sendtime);
					 var k=[];
					 k.push(id);
					 k.push(obj.files[0]);
					 msgcenter.add2box('me',fid,uid,'pic',k,sendtime);
					 */

				},id+"."+format);
				return false;
			}
			$("#inputbox_"+ftype+fid+"_"+uid+" .inputboxcntpage").append("<img class='ready2send_pic' format='"+format+"' name='"+id+"'>");
			
			var fr=new FileReader();
			fr.onload=function(e)
			{
				$("img[name='"+id+"']").attr("src",e.target.result);
				img_ids.add(uid,fid,id,obj.files[0],e.target.result);
			}
			fr.readAsDataURL(obj.files[0]);
			img_ids.viewall();
			//return id;
		}
		//return false;
	}
	

	//窗口抖动动画效果
	var go=function(foid,fid,uid)
	{
		/*
			首先重新绑定震动按钮函数为10秒内禁止按第二次
		*/
		$("#chatframe_"+fid+"_"+uid+" .twitter").unbind('click').click(function()
		{
			console.log('10秒后才可以发第二次');
		});
		//10秒后重新绑定震动函数
		setTimeout(function()
		{
			$("#chatframe_"+fid+"_"+uid+" .twitter").unbind('click').click(function()
			{
				var now=$(this).parent('.midtoolcnt').attr('id');
				var reg=/midtoolcnt_([a-zA-z]+)(\d+)_(\d+)/;
				var cid=reg.exec(now);//cid[0]=chatframe_x_y cid[1]=x cid[2]=y
				//更新当前用户id和好友id
				var uid=parseInt(cid[3]);
				var fid=cid[1]+cid[2];
				var ftype=cid[1];
				var foid=cid[2];

				go(foid,fid,uid);
			});
		},10000);

		//发送震动信息

		sendmsg(uid,foid,'frd','shake','[抖了你一下]',function(msg)
		{
			if(msg.indexOf("ok:time=")>=0)
			{
				//设置震动
				//console.log('震动fid='+fid+" uid="+uid);
				var top=$("#chatframe_"+fid+"_"+uid)[0].offsetTop;
				var left=$("#chatframe_"+fid+"_"+uid)[0].offsetLeft;
				
				var r=10;
				var step=1;
				var fn=function()
				{
					if(step>=21)
					{
						
						clearInterval(start);
						window.clearInterval(start);
						window.clearInterval(this);
						$("#chatframe_"+fid+"_"+uid).css('top',top+'px');
						$("#chatframe_"+fid+"_"+uid).css('left',left+'px');
						return;
					}
					var t=top+r*Math.cos(step);
					var l=left+r*Math.sin(step);
					$("#chatframe_"+fid+"_"+uid).css('top',t+'px');
					$("#chatframe_"+fid+"_"+uid).css('left',l+'px');
					step+=1;
				}

				var start=setInterval(fn,20);

				msg=msg.replace("ok:time=","");
				msgcenter.add2box('me',fid,uid,'shake',0,msg);

			}

		});


		

	}



	//初始化后手动绑定的事件函数
	function bind()
	{
		$(".tobubble").click(function(e)
		{
			if($(this).parent(".switch_font_type").parent().attr("class")=="bubble_type")
			{
				return false;
			}
			$(this).parent(".switch_font_type").parent(".list_type").siblings(".bubble_type").css("display","block");
			$(this).parent(".switch_font_type").parent(".list_type").css("display","none");
			$(this).parent(".switch_font_type").parent(".list_type").parent(".midfontset").parent(".midtoolbar").parent(".chatinput").siblings(".chatbox").find(".chatcntbox>.chatcntpage>.chatbox_msgtype").attr("class","chatbox_msgtype msg_bubble");
			
			
			
			var uid=$(this).parents('.chatframe').attr('id').replace(/chatframe_(\w+)_(\d+)/,'$2');
			//更新到全局数组中
			var uth=usr.getpro(uid,'theme');
			uth['chatmode']=1;
			usr.setpro(uid,'theme',uth);

			//设置到主题设置面板上
			var t=$('#themebox_board_'+uid+' .themebox_selectbubbleortext');
			t.find('.selected').removeClass('selected');
			t.find('.switchleft').addClass('selected');
			$('#themebox_board_'+uid+' .themebox_detail_bubble').removeClass('mod_text').addClass('mod_bubble');
			//设置到所有对话框中
			$('.owner_'+uid+' .chatbox_msgtype').removeClass('msg_list').addClass('msg_bubble');

			//阻止事件触发多次
			e.stopImmediatePropagation();
		});
		$(".tolist").click(function(e)
		{
			if($(this).parent(".switch_font_type").parent().attr("class")=="list_type")
			{
				return false;
			}
			$(this).parent(".switch_font_type").parent(".bubble_type").siblings(".list_type").css("display","block");
			$(this).parent(".switch_font_type").parent(".bubble_type").css("display","none");
			$(this).parent(".switch_font_type").parent(".bubble_type").parent(".midfontset").parent(".midtoolbar").parent(".chatinput").siblings(".chatbox").find(".chatcntbox>.chatcntpage>.chatbox_msgtype").attr("class","chatbox_msgtype msg_list");
			
			
			var uid=$(this).parents('.chatframe').attr('id').replace(/chatframe_(\w+)_(\d+)/igm,'$2');
			//更新到全局数组中
			var uth=usr.getpro(uid,'theme');
			uth['chatmode']=0;
			usr.setpro(uid,'theme',uth);

			//设置到主题设置面板上
			console.log(uid);
			var t=$('#themebox_board_'+uid+' .themebox_selectbubbleortext');
			t.find('.selected').removeClass('selected');
			t.find('.switchright').addClass('selected');
			$('#themebox_board_'+uid+' .themebox_detail_bubble').removeClass('mod_bubble').addClass('mod_text');
			//设置到所有对话框中
			$('.owner_'+uid+' .chatbox_msgtype').removeClass('msg_bubble').addClass('msg_list');
			
			//阻止事件触发多次
			e.stopImmediatePropagation();
		});
		
		$(".adv_hidebar").mouseout(function(e)
		{
			$(this).css("display","none");
			//阻止事件触发多次
			e.stopImmediatePropagation();
		}).click(function(e)
		{
			if($(this).hasClass("chatrighthide"))
			{
				$(this).parents('.chatframe').addClass('temphide');
				$(this).addClass('chatrightshow').removeClass('chatrighthide');
				$(this).attr('title','显示侧边');
			}
			else
			{
				$(this).parents('.chatframe').removeClass('temphide');
				$(this).addClass('chatrighthide').removeClass('chatrightshow');
				$(this).attr('title','隐藏侧边');
			}	

			e.stopImmediatePropagation();
		});



		//鼠标移上图片时添加缩放比例的title
		$(".piccnt").mouseover(function(e)
		{
			//var id=$(this).parents(".chatcntpage").attr("id").replace("chatcntpage");
			var boxwidth=$(this).parents(".chatcntpage")[0].offsetWidth;		
			var im=new Image();
			im.src=$(this).find("img").attr("src");
			var imgsrcwidth=im.width;

			//console.log('boxwidth='+boxwidth+" imgwidth="+imgsrcwidth);
			if(imgsrcwidth<boxwidth-4)
			{
				$(this).find(".pic").attr("title","显示比例 : 100% , 双击查看原图");
			}
			else
			{
				var percent=Math.ceil((((boxwidth*0.85)-4)/imgsrcwidth)*100);
				//console.log("per="+percent);
				$(this).find(".pic").attr("title","显示比例 : "+percent+"% , 双击查看原图");
			}
			//阻止事件触发多次
			e.stopImmediatePropagation();
		});

		
		//$(".sulink").on('mouseover',setsafetag).mouseout();




	}

	

	


}


function _chatrightbind()
{
	/*右侧内容页切换按钮*/
	$('.chatright_tabbtn').click(function(e)
	{
		var rb=$(this).parents('.chatrightbox');
		var t=$(e.target);
		if(t.attr('class')=="chattab_close")
		{
			
			if($(this).hasClass('msghistroy')&&rb.hasClass('page_msghistroy'))
			{
				$(this).parents('.chatframe').find('.msghis').removeClass('clicked').attr('title','显示聊天记录');
				rb.find('.chatframe_msghistroy').remove();
			}
			else if($(this).hasClass('searchmsg')&&rb.hasClass('page_searchmsg'))
			{
				rb.find('.chatframe_searchmsg').remove();
			}
			
			if($(this).siblings('.chatright_tabbtn').length>0)
			{
				var sb=$(this).siblings('.chatright_tabbtn').eq(0);
				var cls=sb.attr('class').replace('chatright_tabbtn ','');
				rb.attr('class','chatrightbox page_'+cls);
			}
			else
			{
				$(this).parents('.chatframe').removeClass('open_chatright');
				
			}
			$(this).remove();

			e.stopImmediatePropagation();
			return;
		}
		else
		{
			if($(this).hasClass('msghistroy'))
			{
				if(rb.hasClass('page_msghistroy'))
				{
					return;
				}
				else
				{
					rb.attr('class','chatrightbox page_msghistroy');
				}

			}
			else if($(this).hasClass('searchmsg'))
			{
				if(rb.hasClass('page_searchmsg'))
				{
					return;
				}
				else
				{
					rb.attr('class','chatrightbox page_searchmsg');
				}
			}
			e.stopImmediatePropagation();
		}
		
	});

	$('.msghistroy_li').click(function(e)
	{
		if($(this).hasClass('selected'))
		{
			return false;
		}
		
		$(this).siblings('.selected').removeClass('selected');
		$(this).addClass('selected');
		e.stopImmediatePropagation();
	});

	//打开搜索条按钮
	$('.msghistroy_searchbtn').click(function(e)
	{
		
		if($(this).hasClass('clicked'))
		{
			$(this).parents('.chatframe_msghistroy').removeClass('open_msghistory_search');
			$(this).removeClass('clicked').attr('title','打开搜索条');
		}
		else
		{
			$(this).parents('.chatframe_msghistroy').addClass('open_msghistory_search');
			$(this).addClass('clicked').attr('title','隐藏搜索条');
		}
		e.stopImmediatePropagation();
	});


	$('.msghistroy_board').mouseover(function()
	{
		Scroll.set($(this),$(this).find('.msghistroy_cnt'),$(this).find('.msghistroy_page'));
	});
	//搜索聊天记录输入框
	$('.searchmsgstr .searchinput').keyup(function(e)
	{
		
		if($.trim($(this).val()).length>0)
		{
			$(this).siblings('.delall').css('display','block');
		}
		else
		{
			$(this).siblings('.delall').css('display','none');
		}
		e.stopImmediatePropagation();
	});
	//删除搜索内容
	$('.searchmsgstr .delall').click(function(e)
	{
		$(this).siblings('.searchinput').val('').focus();
		$(this).css('display','none');
		e.stopImmediatePropagation();
	});

	//确定搜索-------------(此处应该阻止多次重复促发)
	$('.msghistroy_bottomtools .submitsearch').click(function(e)
	{
		var range=$(this).siblings('.msghistroy_range').find('select option:selected').val();
		var searchstr=$.trim($(this).siblings('.searchmsgstr').find('.searchinput').val());
		if(searchstr.length<=0)
		{
			return;
		}
		var cid=/chatframe_([a-zA-Z]+)(\d+)_(\d+)/.exec($(this).parents('.chatframe').attr('id'));
		var type=cid[1];
		var fid=cid[2];
		var uid=cid[3];
		
		var pn=$(this).parents('.chatframe_msghistroy');
		if(pn.find('.msghistroy_board').css('display')=='block')
		{
			pn.find('.msghistroy_board').css('display','none');
		}
		//隐藏翻页板
		$(this).parents('.msghistroy_bottomtools').find('.normalindex').css('display','none');

		pn.find('.msghistroy_searchboard').css('display','block');
		var rs=pn.find('.msghistroy_searchboard .search_result');
		var rp=pn.find('.msghistroy_searchboard .search_rspage');
		rs.css('display','block');
		rs.find('.msghistroy_searchcnt').html('<div class="msghistroy_pageload"></div>');
		rp.css('display','none');
		rp.find('.msghistroy_cnt').html('');
		pn.find('.rstips').html('正在获取中...');
		_ajaxget('u='+uid+'&&f='+fid+'&&t=search&&key='+searchstr+'&&rg='+range,'comet_get',function(m)
		{
			if(m!='no')
			{
				var html='<ul class="msghistroy_searchpage">';
				for(var i=0;i<m.length;i++)
				{
					var content=m[i].content.replace(eval('/'+searchstr+'/gm'),'<span class="key">'+searchstr+'</span>');
					//console.log(content);
					var stime=new Date(m[i].time*1000);
					var st=stime.getFullYear()+'-'+(stime.getMonth()+1)+'-'+stime.getDate()+'&nbsp;'+(stime.getHours()>9?stime.getHours():'0'+stime.getHours())+':'+(stime.getMinutes()>9?stime.getMinutes():'0'+stime.getMinutes())+':'+(stime.getSeconds()>9?stime.getSeconds():'0'+stime.getSeconds());
					var cmname='';
					var iself='';
					if(m[i].fromid==uid&&m[i].toid==fid)
					{
						cmname=usr.getuser(uid).name;
						iself='self';
					}
					else if(m[i].toid==uid&&m[i].fromid==fid)
					{
						cmname=(usr.getaother(uid,fid).frdname==''?usr.getaother(uid,fid).name:usr.getaother(uid,fid).frdname);
					}
					else
					{
						continue;
					}
					html+='<li class="msghistroy_searchli '+iself+'"><div class="msghead">'+cmname+'&nbsp;'+st+'</div><div class="msgcnt">'+content+'</div><a class="hidetips" href="javascript:;" onClick="showrelativemsg('+uid+','+fid+','+m[i].id+',this);">查看前后消息</a></li>';
				
				}
				html+='</ul>';
				pn.find('.rstips').html('已搜索到'+m.length+'条消息记录');
				rs.find('.msghistroy_searchcnt').html(html);
				_chatrightbind();
			}
			else
			{
				pn.find('.rstips').html('没有搜索结果');
				rs.find('.msghistroy_searchcnt').html('');
				
			}
			
		});

		e.stopImmediatePropagation();
	});
	
	$('.msghistroy_searchboard .search_result').mouseover(function()
	{
		Scroll.set($(this),$(this).find('.msghistroy_searchcnt'),$(this).find('.msghistroy_searchpage'));
	});
	$('.msghistroy_searchboard .search_rspage').mouseover(function()
	{
		Scroll.set($(this),$(this).find('.msghistroy_cnt'),$(this).find('.msghistroy_page'));
	});

	//返回到聊天记录页面按钮
	$('.msghistroy_searchtipbar .hidethis').click(function(e)
	{
		var rs=$(this).parents('.msghistroy_searchtipbar').siblings('.search_result');
		var rp=$(this).parents('.msghistroy_searchtipbar').siblings('.search_rspage');
		
		if(rs.css('display')=='block')
		{
			rs.find('.msghistroy_searchcnt').html('');
			$(this).parents('.msghistroy_searchboard').css('display','none');
			$(this).parents('.msghistroy_searchboard').siblings('.msghistroy_board').css('display','block');
			$(this).parents('.msghistroy_searchboard').siblings('.msghistroy_bottomtools').find('.normalindex').css('display','block');
		}
		else if(rp.css('display')=='block')
		{
			rp.find('.msghistroy_cnt').html('');
			rp.css('display','none');
			rs.css('display','block');
			$(this).parents('.msghistroy_searchboard').siblings('.msghistroy_bottomtools').find('.searchindex').css('display','none');
			$(this).siblings('.rstips').css('display','block');
		}
		
		e.stopImmediatePropagation();
	});
	
	//聊天记录翻页按钮
	$('.gopagebtn').click(function(e)
	{
		if($(this).hasClass('disable'))
		{
			return false;
		}
		var cid=/chatframe_([a-zA-Z]+)(\d+)_(\d+)/.exec($(this).parents('.chatframe').attr('id'));
		var type=cid[1];
		var fid=cid[2];
		var uid=cid[3];
		var tocnt=$(this).parents('.msghistroy_pageindexboard').attr('class').replace('msghistroy_pageindexboard ','');
		if($(this).hasClass('firstpage'))
		{
			sethistorybox(uid,fid,type,tocnt,'first');
		}
		else if($(this).hasClass('lastpage'))
		{
			sethistorybox(uid,fid,type,tocnt,'last');
		}
		else if($(this).hasClass('nextpage'))
		{
			sethistorybox(uid,fid,type,tocnt,'next');
		}
		else if($(this).hasClass('thelastpage'))
		{
			sethistorybox(uid,fid,type,tocnt,'thelast');
		}
		
		e.stopImmediatePropagation();
	});
	
	//显示/隐藏日历
	$('.calendarico').click(function(e)
	{
		var ccnt=$(this).siblings('.calendarcontent');
		if($(this).hasClass('clicked')||ccnt.css('display')=='block')
		{
			$(this).removeClass('clicked');
			ccnt.find('.calendarcntbody').html('<div class="calendarcntbody_load"></div>');
			ccnt.css('display','none');
		}
		else
		{
			$(this).addClass('clicked');
			var datadate=$(this).siblings('.calendardate').html();
			setcalendar(datadate,ccnt);
		}
		e.stopImmediatePropagation();
	});
	

}

//切换日历后绑定日期按钮事件
function bindcalendarevent()
{
	$('.datectrl .lastyear').click(function(e)
	{
		if($(this).hasClass('disable'))
		{
			return false;
		}
		var ccnt=$(this).parents('.calendarcontent');
		var dd=$(this).siblings('.nowdate').attr('date');
		dd=dd.replace(/-/g,'/').replace(',',' ');
		dd=new Date(dd);
		var y=dd.getFullYear();
		var m=dd.getMonth()+1;
		var d=dd.getDate();
		var datadate=(y-1)+'-'+m+'-'+d;
		setcalendar(datadate,ccnt);
		e.stopImmediatePropagation();
	});

	$('.datectrl .lastmonth').click(function(e)
	{
		if($(this).hasClass('disable'))
		{
			return false;
		}
		var ccnt=$(this).parents('.calendarcontent');
		var dd=$(this).siblings('.nowdate').attr('date');
		dd=dd.replace(/-/g,'/').replace(',',' ');
		dd=new Date(dd);
		var y=dd.getFullYear();
		var m=dd.getMonth()+1;
		var d=dd.getDate();
		if(m-1<=0)
		{
			m=13;
			y-=1;
		}
		var datadate=y+'-'+(m-1)+'-'+d;
		setcalendar(datadate,ccnt);
		e.stopImmediatePropagation();
	});

	$('.datectrl .nextyear').click(function(e)
	{
		if($(this).hasClass('disable'))
		{
			return false;
		}
		var ccnt=$(this).parents('.calendarcontent');
		var dd=$(this).siblings('.nowdate').attr('date');
		dd=dd.replace(/-/g,'/').replace(',',' ');
		dd=new Date(dd);
		var y=dd.getFullYear();
		var m=dd.getMonth()+1;
		var d=dd.getDate();
		if(y+1>new Date().getFullYear())
		{
			return false;
		}
		var datadate=(y+1)+'-'+m+'-'+d;
		setcalendar(datadate,ccnt);
		e.stopImmediatePropagation();
	});

	$('.datectrl .nextmonth').click(function(e)
	{
		if($(this).hasClass('disable'))
		{
			return false;
		}
		var ccnt=$(this).parents('.calendarcontent');
		var dd=$(this).siblings('.nowdate').attr('date');
		dd=dd.replace(/-/g,'/').replace(',',' ');
		dd=new Date(dd);
		var y=dd.getFullYear();
		var m=dd.getMonth()+1;
		var d=dd.getDate();
		if(m+1>new Date().getMonth()+1)
		{
			m=0;
			if(y+1>new Date().getFullYear())
			{
				return false;
			}
			else
			{
				y+=1;
			}
		}
		var datadate=y+'-'+(m+1)+'-'+d;
		setcalendar(datadate,ccnt);
		e.stopImmediatePropagation();
	});

	$('.calendarcntbody .hasdata').click(function(e)
	{
		var where=$(this).parents('.msghistroy_pageindexboard').attr('class').replace('msghistroy_pageindexboard ','');
		
		var ccnt=$(this).parents('.calendarcontent');
		$(this).parents('.calendarcontent').siblings('.calendardate').html($(this).attr('date'));
		$(this).parents('.calendarcontent').siblings('.calendarico').removeClass('clicked');
		ccnt.find('.calendarcntbody').html('<div class="calendarcntbody_load"></div>');
		ccnt.css('display','none');

		

		var sb=$(this).parents('.msghistroy_bottomtools').siblings('.msghistroy_searchboard');
		sb.find('.search_result').css('display','none');
		sb.find('.search_rspage').css('display','block');
		sb.find('.search_rspage .msghistroy_cnt').html('<div class="msghistroy_pageload"></div>');
		sb.siblings('.msghistroy_bottomtools').find('.searchindex').css('display','block');
		sb.find('.rstips').css('display','none');
		
		var gobtn=$(this).parents('.msghistroy_date').siblings('.msghistroy_gopage');
		var fp=gobtn.find('.firstpage');
		var lp=gobtn.find('.lastpage');
		var np=gobtn.find('.nextpage');
		var tp=gobtn.find('.thelastpage');
		var cid=/chatframe_([a-zA-Z]+)(\d+)_(\d+)/.exec(ccnt.parents('.chatframe').attr('id'));
		var type=cid[1];
		var fid=cid[2];
		var uid=cid[3];
		
		
		_ajaxget('u='+uid+'&&f='+fid+'&&t=gbd&&d='+$(this).attr('date'),'comet_get',function(m)
		{
			if(m)
			{
				//console.log(m);

				if(parseInt(m.last)==1)
				{
					fp.removeClass('disable').attr('title','第一页');
					lp.removeClass('disable').attr('title','上页').attr('of',m.cms[0].id);
				}
				else
				{
					fp.addClass('disable').attr('title','已经是第一页了');
					lp.addClass('disable').attr('title','没有上页了').attr('of','');
				}

				if(parseInt(m.next)==1)
				{
					tp.removeClass('disable').attr('title','最后一页');
					np.removeClass('disable').attr('title','下页').attr('of',m.cms[m.cms.length-1].id);
				}
				else
				{
					tp.addClass('disable').attr('title','已经是最后一页了');
					np.addClass('disable').attr('title','没有下页了').attr('of','');
				}
				var stime=new Date(m['cms'][0].time*1000);
				var fulldate=stime.getFullYear()+'-'+(stime.getMonth()>8?(stime.getMonth()+1):'0'+(stime.getMonth()+1))+'-'+(stime.getDate()>9?stime.getDate():'0'+stime.getDate());
				sb.siblings('.msghistroy_bottomtools').find('.'+where+' .calendardate').html(fulldate);
				_add2historybox(uid,fid,'frd',m['cms'],where);
			}
			else
			{

			}
		});


		e.stopImmediatePropagation();
	});
}

//设置日历函数
function setcalendar(datadate,ccnt)
{
	var cid=/chatframe_([a-zA-Z]+)(\d+)_(\d+)/.exec(ccnt.parents('.chatframe').attr('id'));
	var type=cid[1];
	var fid=cid[2];
	var uid=cid[3];
	
	ccnt.css('display','block');
	var ly=ccnt.find('.lastyear');
	var lm=ccnt.find('.lastmonth');
	var ny=ccnt.find('.nextyear');
	var nm=ccnt.find('.nextmonth');

	//var datadate=$(this).siblings('.calendardate').html();
	datadate=datadate.replace(/-/g,'/').replace(',',' ');
	datadate=new Date(datadate);
	//设置年月翻页按钮是否可用
	var nowdate=new Date();
	(datadate.getFullYear()<nowdate.getFullYear())?ny.attr('title','下一年').removeClass('disable'):ny.attr('title','没有下一年了').addClass('disable');
	(datadate.getFullYear()==nowdate.getFullYear()&&datadate.getMonth()<nowdate.getFullYear())||(datadate.getFullYear()<nowdate.getFullYear())?nm.attr('title','下一个月').removeClass('disable'):nm.attr('title','没有下一个月了').addClass('disable');
	//设置日历年月标头
	var mstr='';
	var days=31;
	switch(datadate.getMonth())
	{
		case 0:
			mstr='一';
			break;
		case 1:
			mstr='二';
			days-=((datadate.getFullYear()%4==0&&datadate.getFullYear()%100!=0)||(datadate.getFullYear()%400==0))?2:3;
			break;
		case 2:
			mstr='三';
			break;
		case 3:
			mstr='四';
			days-=1;
			break;
		case 4:
			mstr='五';
			break;
		case 5:
			mstr='六';
			days-=1;
			break;
		case 6:
			mstr='七';
			break;
		case 7:
			mstr='八';
			break;
		case 8:
			mstr='九';
			days-=1;
			break;
		case 9:
			mstr='十';
			break;
		case 10:
			mstr='十一';
			days-=1;
			break;
		case 11:
			mstr='十二';
			break;
		default:
			mstr='一';
	}
	mstr=mstr+'月';
	ccnt.find('.nowdate .monthstr').html(mstr);
	ccnt.find('.nowdate .yearstr').html(datadate.getFullYear());
	ccnt.find('.nowdate').attr('date',datadate.getFullYear()+'/'+(datadate.getMonth()+1)+'/1');
	//添加日期并检查信息
	var week=new Date(datadate.getFullYear()+'/'+(datadate.getMonth()+1)+'/1').getDay();
	//0 1 2 3 4 5 6  0
	_ajaxget('u='+uid+'&&f='+fid+'&&t=getdate&&d='+datadate.getFullYear()+'-'+(datadate.getMonth()+1)+'-1','comet_get',function(ds)
	{
		var table='<table cellspacing="0" cellpadding="0"><tr>';
		for(var i=0,d=1;i<42;i++)
		{
			if(i<6)
			{
				if(i<week)
				{
					table+='<td>&nbsp;</td>';
				}
				else
				{
					table+='<td'+((ds!='no'&&ds.in_array('day',d+''))?' class="hasdata" date="'+(datadate.getFullYear()+'-'+(datadate.getMonth()+1)+'-'+d)+'"':'')+'>'+d+'</td>';
					d+=1;
				}
			}
			else
			{
				if(d<=days)
				{
					table+='<td'+((ds!='no'&&ds.in_array('day',d+''))?' class="hasdata" date="'+(datadate.getFullYear()+'-'+(datadate.getMonth()+1)+'-'+d)+'"':'')+'>'+d+'</td>';
					d+=1;
				}
				else
				{
					table+='<td>&nbsp;</td>';
				}
			}

			if(i>0&&(i+1)%7==0&&i<41)
			{
				table+='</tr><tr>';
			}
		}

		table+='</tr></table>';
		ccnt.find('.calendarcntbody').html(table);
		bindcalendarevent();
	});
}


function sethistorybox(uid,fid,type,tocnt,addtype)
{
	//console.log(tocnt);
	var cf=$('#chatframe_'+type+fid+'_'+uid);
	var cntcss=tocnt=="normalindex"?'.msghistroy_board':'.msghistroy_searchboard .search_rspage';
	var cnt=cf.find('.chatframe_msghistroy '+cntcss+' .msghistroy_cnt');
	cnt.html('<div class="msghistroy_pageload"></div>');
	type==undefined?type='frd':'';
	var gobtn=cf.find('.'+tocnt+' .msghistroy_gopage');
	var fp=gobtn.find('.firstpage');
	var lp=gobtn.find('.lastpage');
	var np=gobtn.find('.nextpage');
	var tp=gobtn.find('.thelastpage');

	var offset=0;
	var desc=-1;
	if(addtype!=undefined)
	{
		if(addtype=='next')
		{
			desc=1;
			offset=np.attr('of');
		}
		else if(addtype=='last')
		{
			desc=0;
			offset=lp.attr('of');
		}

		else if(addtype=='first')
		{
			desc=1;
		}
		else if(addtype=='thelast')
		{
			
		}
	}
	//console.log(offset+','+desc+','+addtype);

	_ajaxget('u='+uid+'&&f='+fid+'&&t=g60&&of='+offset+'&&dc='+desc,'comet_get',function(m)
	{
		if(m)
		{
			//console.log(m);

			if(parseInt(m.last)==1)
			{
				fp.removeClass('disable').attr('title','第一页');
				lp.removeClass('disable').attr('title','上页').attr('of',m.cms[0].id);
			}
			else
			{
				fp.addClass('disable').attr('title','已经是第一页了');
				lp.addClass('disable').attr('title','没有上页了').attr('of','');
			}

			if(parseInt(m.next)==1)
			{
				tp.removeClass('disable').attr('title','最后一页');
				np.removeClass('disable').attr('title','下页').attr('of',m.cms[m.cms.length-1].id);
			}
			else
			{
				tp.addClass('disable').attr('title','已经是最后一页了');
				np.addClass('disable').attr('title','没有下页了').attr('of','');
			}
			_add2historybox(uid,fid,'frd',m['cms'],tocnt);
		}
		else
		{

		}
	});
}


function _add2historybox(uid,senderid,type,cm,tocnt,flagid)
{
	flagid==undefined?flagid=0:'';
	var cf=$('#chatframe_'+type+senderid+'_'+uid);
	var cntcss=tocnt=="normalindex"?'.msghistroy_board':'.msghistroy_searchboard .search_rspage';
	var cnt=cf.find('.chatframe_msghistroy '+cntcss+' .msghistroy_cnt');
	//var cnt=cf.find('.chatframe_msghistroy .msghistroy_cnt');
	var page='<ul class="msghistroy_page">';
	if(type=="frd")
	{
		//for(var i=cm.length-1;i>=0;i--)
		var tempdate=0;
		for(var i=0;i<cm.length;i++)
		{
			var html='';
			//var dvalue=Math.floor(((new Date().getTime())-cm[i].time*1000)/(1000 * 60 * 60 * 24));
			var dvalue=Math.floor((cm[i].time*1000-tempdate)/(1000 * 60 * 60 * 24));
			//console.log(dvalue);
			var stime=new Date(cm[i].time*1000);
			if(dvalue>=1)
			{
				var fulldate=stime.getFullYear()+'-'+(stime.getMonth()>8?(stime.getMonth()+1):'0'+(stime.getMonth()+1))+'-'+(stime.getDate()>9?stime.getDate():'0'+stime.getDate());
				html+='<li class="dateline" date="'+fulldate+'"><div class="lineimg">'+fulldate+'</div></li>';
				tempdate=cm[i].time*1000;
			}
			var st=(stime.getHours()>9?stime.getHours():'0'+stime.getHours())+':'+(stime.getMinutes()>9?stime.getMinutes():'0'+stime.getMinutes())+':'+(stime.getSeconds()>9?stime.getSeconds():'0'+stime.getSeconds());
			if(cm[i].fromid==uid&&cm[i].toid==senderid)
			{
				html+='<li class="msghistroy_li self '+(flagid==cm[i].id?'selected':'')+'"><div class="msghead">'+usr.getuser(uid).name+'&nbsp;&nbsp;'+st+'</div><div class="msgcnt">'+msgcenter.msgfilter(cm[i].content)+'</div></li>';
			}
			else if(cm[i].toid==uid&&cm[i].fromid==senderid)
			{
				html+='<li class="msghistroy_li '+(flagid==cm[i].id?'selected':'')+'"><div class="msghead">'+(usr.getaother(uid,senderid).frdname==''?usr.getaother(uid,senderid).name:usr.getaother(uid,senderid).frdname)+'&nbsp;&nbsp;'+st+'</div><div class="msgcnt">'+msgcenter.msgfilter(cm[i].content)+'</div></li>';
			}
			page+=html;
		}
	}

	page+='</ul>';
	cnt.html(page);
	_chatrightbind();

}


//获取搜索聊天记录结果条目的上下文
function showrelativemsg(uid,fid,cmid,o)
{
	//console.log(uid+','+fid+','+cmid);
	//console.log(o);
	var sb=$(o).parents('.msghistroy_searchboard');
	sb.find('.search_result').css('display','none');
	sb.find('.search_rspage').css('display','block');
	sb.find('.search_rspage .msghistroy_cnt').html('<div class="msghistroy_pageload"></div>');
	sb.siblings('.msghistroy_bottomtools').find('.searchindex').css('display','block');
	sb.find('.rstips').css('display','none');

	
	var gobtn=sb.siblings('.msghistroy_bottomtools').find('.searchindex .msghistroy_gopage');
	var fp=gobtn.find('.firstpage');
	var lp=gobtn.find('.lastpage');
	var np=gobtn.find('.nextpage');
	var tp=gobtn.find('.thelastpage');

	_ajaxget('u='+uid+'&&f='+fid+'&&t=gbt60&&cmid='+cmid,'comet_get',function(m)
	{
		if(m)
		{
			console.log(m);

			if(parseInt(m.last)==1)
			{
				fp.removeClass('disable').attr('title','第一页');
				lp.removeClass('disable').attr('title','上页').attr('of',m.cms[0].id);
			}
			else
			{
				fp.addClass('disable').attr('title','已经是第一页了');
				lp.addClass('disable').attr('title','没有上页了').attr('of','');
			}

			if(parseInt(m.next)==1)
			{
				tp.removeClass('disable').attr('title','最后一页');
				np.removeClass('disable').attr('title','下页').attr('of',m.cms[m.cms.length-1].id);
			}
			else
			{
				tp.addClass('disable').attr('title','已经是最后一页了');
				np.addClass('disable').attr('title','没有下页了').attr('of','');
			}
			var stime=new Date(m['cms'][0].time*1000);
			var fulldate=stime.getFullYear()+'-'+(stime.getMonth()>8?(stime.getMonth()+1):'0'+(stime.getMonth()+1))+'-'+(stime.getDate()>9?stime.getDate():'0'+stime.getDate());
			sb.siblings('.msghistroy_bottomtools').find('.searchindex .calendardate').html(fulldate);
			_add2historybox(uid,fid,'frd',m['cms'],'searchindex',cmid);
		}
		else
		{

		}
	});
}


	/*	function ChatScroll(uid,fid)
		{
			var frame=$('#chatbox_'+fid+'_'+uid).find('.scrollframe');
			var block=$('#chatbox_'+fid+'_'+uid).find('.scrollblock');

			var frameh=frame[0].offsetHeight;
			
			var win=$('#chatbox_'+fid+'_'+uid)[0].clientHeight;
			var page=$("#chatbox_"+fid+"_"+uid+" .chatcntpage")[0].offsetHeight;

			var offset=win-page;


			this.resize=function(uid,fid)
			{
				
				win=$('#chatbox_'+fid+'_'+uid)[0].clientHeight;
				page=$("#chatbox_"+fid+"_"+uid+" .chatcntpage")[0].offsetHeight;
				//pageTop=$("#chatbox_"+fid+"_"+uid+" .chatcntpage")[0].offsetTop;
				pageTop=parseInt($("#chatbox_"+fid+"_"+uid+" .chatcntpage").css('top').replace('px','').replace('-',''));
				console.log('pageTop'+pageTop);
				offset=win-page;
				if(offset==0)
				{
					$("#chatbox_"+fid+"_"+uid+" .chatcntscroll").css('display','none');
					return false;
				}
				else
				{
					$("#chatbox_"+fid+"_"+uid+" .chatcntscroll").css('display','block');
				}
				//重设滚动条高度
				$('#chatbox_'+fid+'_'+uid).find('.scrollframe').css('height',(win-24)+'px');
				$('#chatbox_'+fid+'_'+uid).find('.scrollbar').css('height',(win-48)+'px');

				frameh=$('#chatbox_'+fid+'_'+uid).find('.scrollframe')[0].offsetHeight;
				//判断滚动偏移，以重设滚轮大小和方位

				//计算滚动高度
				var blockh=Math.abs(win/page)*(win-48);
				console.log('blockh'+blockh);
				$('#chatbox_'+fid+'_'+uid).find('.scrollblock').css('height',blockh+'px');
				//计算滚轮偏移
				var per=pageTop/page;
				blocktop=per*(win-48);
				console.log('blocktop'+blocktop);
				$('#chatbox_'+fid+'_'+uid).find('.scrollblock').css('top',blocktop+'px');

				window.onmousewheel=document.onmousewheel=function(e)
				{
					e=e||window.event;
					if(e.wheelDelta)
					{
						scroll(e.wheelDelta);
					}
					else if(e.detail)
					{
						scroll(e.detail);
					}
				}
				function scroll(x)
				{
					if(Math.abs(x)==120)
					{
						var step=0;
						var blockh=$('#chatbox_'+fid+'_'+uid).find('.scrollblock')[0].offsetHeight;
						var blockt=parseInt($('#chatbox_'+fid+'_'+uid).find('.scrollblock').css('top').replace('px',''));
						var barh=$('#chatbox_'+fid+'_'+uid).find('.scrollbar')[0].offsetHeight;

						//已经走过的高度
						var runed=blockt;
						//剩余高度
						var left=barh-runed;
						
						if(x>0)
						{
							step=-0.02;
						}
						else
						{
							step=0.02;
						}
						var per=runed/barh+step;
							

						if(per<=0)
						{
							per=0;
							//get history
						}
						if(per>=1)
						{
							per=1;
						}
						var go=per*barh;
						if(go>=(barh-blockh))
						{
							go=barh-blockh;
						}
						var topover=-per*$("#chatbox_"+fid+"_"+uid+" .chatcntpage")[0].offsetHeight;
						if(-topover>=$("#chatbox_"+fid+"_"+uid+" .chatcntpage")[0].offsetHeight)
						{
							topover=-$("#chatbox_"+fid+"_"+uid+" .chatcntpage")[0].offsetHeight
						}

						$('#chatbox_'+fid+'_'+uid).find('.scrollblock').css('top',go+'px');
						$("#chatbox_"+fid+"_"+uid+" .chatcntpage").css('top',topover+'px');
						

						

					}
					else if(Math.abs(x)==3)
					{

					}
				}



				
			}
			


		}*/


		
		/*
			链接安全性提示面板sulink mouseout事件2015/8/11
		*/
		function displaysafetag(e)
		{
			//console.log(e.target);
			if($(e.target).find(".safetagboard").length>0)
			{
				$(e.target).find(".safetagboard").remove();
			}
			//阻止事件触发多次
			e.stopImmediatePropagation();
		}
		/*
		链接安全提示面板初始化事件，供sulink mouseover事件绑定2015/8/11
		*/
		function setsafetag(e)
		{
			var x=e.pageX;
			var y=e.pageY;

			var winX=window.innerWidth||document.body.clientWidth;
			var winY=window.innerHeight||document.body.clientHeight;

			var maxX=winX-x;
			var maxY=winY-y;

			var bg=null;
			var top=0;
			var left=0;
			if(x<maxX&&x>maxX/2)
			{	
				if(y>125)
				{
					bg='url(img/Safe/tips4.png)center center no-repeat';
					top=y;
					
				}
				else if(y<125)
				{
					bg='url(img/Safe/tips3.png)center center no-repeat';
					top=y-125;
				}
				left=x-245;
			}
			else if(x>=0&&x<=maxX/2)
			{
				if(y>125)
				{
					bg='url(img/Safe/tips2.png)center center no-repeat';
					top=y-125
				}
				else if(y<125)
				{
					bg='url(img/Safe/tips.png)center center no-repeat';
					top=y;
				}
				left=x-25;
			}
			else if(x>maxX)
			{
				if(y>125)
				{
					bg='url(img/Safe/tips4.png)center center no-repeat';
					top=y;
					
				}
				else if(y<125)
				{
					bg='url(img/Safe/tips3.png)center center no-repeat';
					top=y-125;
				}
				left=x-245;
			}
			


			var tag=$(this).find(".linksafeflag").attr("class").split(" ")[1];
			var tips=null;
			var ctrl='';
			switch(tag)
			{
				case 'safe':
					tips='安全网站 , 可以访问';
					ctrl='<div class="tag_copy">复制</div><div class="tag_collect">收藏</div><div class="tag_report">举报</div>';
					break;
				case 'notsafe':
					tips='';
					ctrl='<div class="tag_copy">复制</div><div class="tag_collect">收藏</div><div class="tag_report">举报</div><div class="tag_whyunknow">为什么未知?</div>';
					break;
				case 'notice':
					tips='';
					ctrl='<div class="tag_copy">复制</div><div class="tag_collect">收藏</div><div class="tag_report">举报</div><div class="tag_whyunknow">为什么未知?</div>';
					break;
				case 'auth':
					tips='官方认证 , 可放心访问';
					ctrl='<div class="tag_copy">复制</div><div class="tag_collect">收藏</div><div class="tag_report">举报</div>';
					break;
				case 'unknow':
					tips='安全性未知 , 谨慎访问';
					ctrl='<div class="tag_report">举报</div><div class="tag_whyunknow">为什么未知?</div>';
					break;
				default:
					tips='安全性未知 , 谨慎访问';
					ctrl='<div class="tag_report">举报</div><div class="tag_whyunknow">为什么未知?</div>';
			}

			$(e.target).append(
				'<div class="safetagboard '+tag+'tag">'+
				'<div class="safetips">'+
				'<div class="tipimg"></div>'+
				'<div class="tipcnt">'+tips+'</div>'+
				'<div class="clear"></div>'+
				'</div>'+
				'<div class="tagctrl">'+
				'<div class=" tag_open">打开</div>'+
				ctrl+
				'<div class="clear"></div>'+
				'</div>'+
				'<div class="clear"></div>'+
				'<div class="safeadv">'+
				'<img src="img/Safe/PCMgr_logo.png"/>全国人民都在用椒椒软件管家，赶快<a href="#">下载</a>吧'+
				'</div></div>'
			);
			$(e.target).find(".safetagboard").css('background',bg).css('top',top+"px").css('left',left+"px");
			//console.log('top='+top+" left="+left);
			//阻止事件触发多次
			e.stopImmediatePropagation();

		}


		/*
			图片预览方法2015/8/12
		*/
		function openimageview(e)
		{
			new createImageView().init(e);
		}




function addhistory2chatbox(loadobj,uid,fid,type,cmid,num)
{
	if($("#chatframe_"+type+fid+"_"+uid+" .chatbox_msgtype .msgcnt").length>=100)
	{
		if($("#chatframe_"+type+fid+"_"+uid+" .midtoolcnt .msghis").hasClass('clicked'))
		{
			loadobj.attr('class','showhistorylink sh_ended cantload');
		}
		else
		{
			loadobj.attr('class','showhistorylink sh_end cantload');
		}
	}
	if(!loadobj.hasClass('cantload')&&$("#chatframe_"+type+fid+"_"+uid+" .chatbox_msgtype .msgcnt").length<100)
	{
		loadobj.attr('class','showhistorylink sh_load cantload');
		_ajaxget('u='+uid+'&&f='+fid+'&&t=getuper&&need='+num+'&&of='+cmid,'comet_get',function(m)
		{
			//console.log(m);
			if(m)
			{
				
				for (var i=0;i<m.cms.length;i++)
				{
					var cms=m.cms[i];
					//2015/12/13,15:50:06
					var t=new Date(cms.time*1000);
					var time=t.getFullYear()+'/'+(t.getMonth()+1)+'/'+t.getDate()+','+(t.getHours()<10?'0'+t.getHours():t.getHours())+':'+(t.getMinutes()<10?'0'+t.getMinutes():t.getMinutes())+':'+(t.getSeconds()<10?'0'+t.getSeconds():t.getSeconds());
					var who=uid==cms.fromid?'me':'frd';
					msgcenter.add2box(cms.id,who,type+fid,uid,cms.mode,cms.content,time,true);
				}
				if(m.last)
				{
					loadobj.attr('class','showhistorylink sh_link');
				}
				else
				{
					if($("#chatframe_"+type+fid+"_"+uid+" .midtoolcnt .msghis").hasClass('clicked'))
					{
						loadobj.attr('class','showhistorylink sh_ended cantload');
					}
					else
					{
						if($("#chatframe_"+type+fid+"_"+uid+" .chatbox_msgtype .chatmsgli").length>=100)
						{
							loadobj.attr('class','showhistorylink sh_end cantload');
						}
					}
				}
			}
			else
			{
				loadobj.attr('class','showhistorylink sh_fail');
			}
		});
	}
}


		

		/*
			设置滚动事件
		*/
		function setScroll(uid,fid,box,pagecnt,cntscroll,scrollframe,scrollbar,scrollblock,elsecase)
		{
				
				var win=$('#'+box+'_'+fid+'_'+uid)[0].clientHeight;
				var page=$('#'+box+'_'+fid+'_'+uid+' .'+pagecnt)[0].offsetHeight;
			
				var pageTop=null;
			
				var offset=win-page;
				//console.log(box+":"+win+","+page);
				//console.log('offset='+offset);
				if(offset==0)
				{
					$('#'+box+'_'+fid+'_'+uid+' .'+cntscroll).css('display','none');
					//return false;
				}
				else
				{
					$('#'+box+'_'+fid+'_'+uid+' .'+cntscroll).css('display','block');
				}
				//重设滚动条高度
				//if(cntscroll!=scrollframe)
				//{
					elsecase=elsecase*4;
					pageTop=parseInt($('#'+box+'_'+fid+'_'+uid+' .'+pagecnt).css('top').replace('px','').replace('-',''));
					$('#'+box+'_'+fid+'_'+uid).find('.'+scrollframe).css('height',(win-elsecase/2)+'px');
				/*}
				else
				{
					//pageTop=$('#'+box+'_'+fid+'_'+uid+' .'+pagecnt).scrollTop();
					pageTop=Math.abs(offset);
					elsecase=elsecase*2;
				}*/
				$('#'+box+'_'+fid+'_'+uid).find('.'+scrollbar).css('height',(win-elsecase)+'px');

			
				//判断滚动偏移，以重设滚轮大小和方位

				//计算滚轮高度(滑块长度)
				/*
					 显示高度      滚动滑块长度
					---------- == --------------
					页面总高度     滚动条总长度(显示高度-上下按钮高度)

					得出 【滑块长度=显示高度*(显示高度-上下按钮高度)/页面总高度】

				*/
				var blockh=Math.abs(win/page)*(win-elsecase);
		
				$('#'+box+'_'+fid+'_'+uid).find('.'+scrollblock).css('height',blockh+'px');
				//计算滚轮偏移
				var per=pageTop/page;
				var blocktop=per*(win-elsecase);
				//console.log('pageTop='+pageTop+' page='+page+' blocktop='+blocktop);
				$('#'+box+'_'+fid+'_'+uid).find('.'+scrollblock).css('top',blocktop+'px');
				

				//var canscroll=true;

				window.onmousewheel=document.onmousewheel=function(e)
				{
					e=e||window.event;
					if(e.wheelDelta)
					{
						scroll(e.wheelDelta);
					}
					else if(e.detail)
					{
						scroll(e.detail);
					}
				}

				function scroll(x)
				{

					if(Math.abs(x)==120)
					{
						var step=0;
						var blockh=$('#'+box+'_'+fid+'_'+uid).find('.'+scrollblock)[0].offsetHeight;
						var blockt=parseInt($('#'+box+'_'+fid+'_'+uid).find('.'+scrollblock).css('top').replace('px',''));
						var barh=$('#'+box+'_'+fid+'_'+uid).find('.'+scrollbar)[0].offsetHeight;

						//已经走过的高度
						var runed=blockt;
						//剩余高度
						var left=barh-runed;

						var pn=$('#'+box+'_'+fid+'_'+uid+' .'+pagecnt);
						var frdid=fid.replace('grp','').replace('frd','').replace('dis','');
						if(x>0)
						{
							if(blockh<=0)
							{
								if(pn.find('.sendtime_cnt').length<=0)
								{
									addhistory2chatbox(pn.find('.showhistorylink'),uid,frdid,'frd',0,3);
								}
								else
								{
									var msgcnt=$("#chatframe_"+fid+"_"+uid+" .chatbox_msgtype .msgcnt");
									//console.log('消息数='+msgcnt.length);
									addhistory2chatbox(pn.find('.showhistorylink'),uid,frdid,'frd',msgcnt.eq(0).attr('cmid'),25);
								}
								return false;
							}
							step=-0.02;
						}
						else
						{
							step=0.02;
						}
						var per=runed/barh+step;
							

						if(per<0)
						{
							per=0;
							//get history
						}
						if(per>=1)
						{
							per=1;
						}
						var go=per*barh;
						if(go>=(barh-blockh))
						{
							go=barh-blockh;
						}
						var topover=-per*$('#'+box+'_'+fid+'_'+uid+' .'+pagecnt)[0].offsetHeight;
						if(-topover>=$('#'+box+'_'+fid+'_'+uid+' .'+pagecnt)[0].offsetHeight)
						{
							topover=-$('#'+box+'_'+fid+'_'+uid+' .'+pagecnt)[0].offsetHeight;
						}
						
						//console.log('per='+per);
						//console.log('go='+go);
						//console.log('topover='+topover);
						//console.log();
						$('#'+box+'_'+fid+'_'+uid).find('.'+scrollblock).css('top',go+'px');
						$('#'+box+'_'+fid+'_'+uid+' .'+pagecnt).css('top',topover+'px');
						if(topover>=0)
						{
							var msgcnt=$("#chatframe_"+fid+"_"+uid+" .chatbox_msgtype .msgcnt");
							//console.log('消息数='+msgcnt.length);
							addhistory2chatbox(pn.find('.showhistorylink'),uid,frdid,'frd',msgcnt.eq(0).attr('cmid'),25);
						}
						if($('#'+box+'_'+fid+'_'+uid+' .'+pagecnt)[0].offsetHeight-$('#'+box+'_'+fid+'_'+uid)[0].offsetHeight+topover<=60)
						{
							$('#'+box+'_'+fid+'_'+uid+' .chatcntbox .chatbottomnewtipsbar').css('display','none');
						}
						

					}
					else if(Math.abs(x)==3)
					{

					}
				}
			

		}

		function setinputScroll()
		{


		}





		function createImageView()
		{

			var img_arr=null;
			var ts=null;
			var thisindex=0;

			var name=null;
			var cntbox=null;

			this.init=function(e)
			{
				_setparam(e);
				_createbox();
				_bind();
			}


			var _createbox=function()
			{
				$(".imageviewboard").remove();
				$('body').append(
					'<div class="imageviewboard" id="imageviewboard">'+
					'<div class="imagecntboard">'+
					'<img class="image2view" src="'+img_arr[thisindex].src+'"/>'+
					'<div class="imageviewclose"></div>'+
					'<div class="lastpic">'+
					'<div class="imagetable">'+
					'<div class="imagecell">'+
					'<div class="lastpicbtn"></div>'+
					'</div></div></div>'+
					'<div class="nextpic">'+
					'<div class="imagetable">'+
					'<div class="imagecell">'+
					'<div class="nextpicbtn"></div>'+
					'</div></div></div>'+
					'<div class="imagebottom">'+
					'<div class="imagetool">'+
					'<div class="imagetoolbg"></div>'+
					'<div class="imagetoolcnt">'+
					'<div class="imagetoolbtn1 image100"></div>'+
					'<div class="imagetoolbtn1 imagefull"></div>'+
					'<div class="imagetoolbtn1 imageroll"></div>'+
					'<div class="imagesplit"></div>'+
					'<div class="imagetoolbtn2 imagesave"></div>'+
					'<div class="imagetoolbtn2 imagecollect"></div>'+
					'<div class="imagetoolbtn2 imagesend2phone"></div>'+
					'<div class="imagetoolbtn2 imageshare"></div>'+
					'<div class="clear"></div></div></div></div></div></div>'
				);

				var winX=window.innerWidth||document.body.clientWidth;
				var winY=window.innerHeight||document.body.clientHeight;

				var x=$(".imageviewboard")[0].offsetWidth;
				var y=$(".imageviewboard")[0].offsetHeight;

				var left=(winX-x)/2;
				var top=(winY-y)/2-(winY-y)/2*0.4;
				$(".imageviewboard").css('top',top+"px").css('left',left+"px");
				
			}
			
			var _setparam=function(e)
			{
				ts=e.currentTarget||e.target;

				name=$(ts).attr('class');
				cntbox=$(ts).parents('.chatbox_msgtype');

				var imgs=null;
				imgs=cntbox.find('img');

				img_arr=[];

				for(var i=0;i<imgs.length;i++)
				{
					var n=imgs.eq(i).attr("name")||imgs.eq(i).attr("id");
					if(n!=null&&n!=undefined&&n.indexOf('imgview_')>=0)
					{
						var a={};
						a.src=imgs.eq(i).attr("src");
						a.width=null;
						img_arr.push(a);

						var thisi=img_arr.length-1;
						if(name=="pic")
						{
							/*console.log("-----------"+name+"-------------");
							console.log($(ts).find('.showaimg').eq(0));
							console.log(imgs.eq(i));
							console.log("---------------------------------");
							*/
							if($(ts).find('.showaimg').eq(0).attr("name")==imgs.eq(i).attr("name")||$(ts).find('.showaimg').eq(0).attr("id")==imgs.eq(i).attr("id"))
							{
								////console.log('相等');
								thisindex=thisi;
							}
						}
						else if(name=="spic")
						{
							if(ts==imgs[i])
							{
								thisindex=thisi;
							}
						}
						else if(name=="openview")
						{
							if($(ts).parent('.loadimg').siblings('img')[0]==imgs[i])
							{
								thisindex=thisi;
							}
						}
					}
					
					
				}
			
			}





			var _bind=function()
			{
				$(".imageviewclose").click(function()
				{
					$(this).parents('.imageviewboard').hide('normal',function()
					{
						$(this).remove();
					});
				});
				//禁止拖出图片
				$(".image2view")[0].ondragstart=function(){return false;}
				//设置拖拽
				drag($(".imageviewboard"));

				$(".image2view").click(function()
				{
					$(this).next(".imageviewclose").trigger('click');
				});
				
				$(".lastpicbtn").mouseover(function(e)
				{
					img_arr=searchimg(cntbox);
					if(thisindex>0&&img_arr[thisindex-1]!=undefined&&img_arr[thisindex-1]!=null)
					{
						$(this).attr("title",parseInt(thisindex)+"/"+img_arr.length);
						$(this).click(function(e)
						{
							if(thisindex>0&&img_arr[thisindex-1]!=undefined&&img_arr[thisindex-1]!=null)
							{
								var w=img_arr[thisindex-1].width==null?false:img_arr[thisindex-1].width+"px";
								$(this).parents('.lastpic').siblings('.image2view').attr('src',img_arr[thisindex-1].src);
								if(w)$(this).parents('.lastpic').siblings('.image2view').css('width',w);
								thisindex=thisindex-1;
								if(thisindex-1<0)
								{
									$(this).attr("title","在消息记录中查看");
									$(this).unbind('click');
								}
								else
								{
									$(this).attr("title",parseInt(thisindex-1)+"/"+img_arr.length);
								}
							}
							else
							{
								$(this).attr("title","在消息记录中查看");
								$(this).unbind('click');
							}
							//阻止事件触发多次
							e.stopImmediatePropagation();
						});
						
					}
					else
					{
						$(this).attr("title","在消息记录中查看");
						$(this).unbind('click');
					}
					//阻止事件触发多次
					e.stopImmediatePropagation();
				});

				$(".nextpicbtn").mouseover(function(e)
				{
					img_arr=searchimg(cntbox);
					if(thisindex<(img_arr.length-1)&&img_arr[thisindex+1]!=undefined&&img_arr[thisindex+1]!=null)
					{
						$(this).attr("title",parseInt(thisindex+2)+"/"+img_arr.length);
						$(this).click(function(e)
						{
							if(thisindex<(img_arr.length-1)&&img_arr[thisindex+1]!=undefined&&img_arr[thisindex+1]!=null)
							{
								var w=img_arr[thisindex+1].width==null?null:img_arr[thisindex+1].width+"px";
								$(this).parents('.nextpic').siblings('.image2view').attr('src',img_arr[thisindex+1].src);
								if(w)$(this).parents('.nextpic').siblings('.image2view').css('width',w);
								thisindex=thisindex+1;
								if(thisindex+2>img_arr.length)
								{
									$(this).attr("title","已经是最后一张");
									$(this).unbind('click');
								}
								else
								{
									$(this).attr("title",parseInt(thisindex+1)+"/"+img_arr.length);
								}
							}
							else
							{
								$(this).attr("title","已经是最后一张");
								$(this).unbind('click');
							}
							//阻止事件触发多次
							e.stopImmediatePropagation();
						});
						
					}
					else
					{
						$(this).attr("title","已经是最后一张");
						$(this).unbind('click');
					}
					//阻止事件触发多次
					e.stopImmediatePropagation();
				});



				$(".imageviewboard").mouseover(function()
				{

				});
			}




			function searchimg(cntbox)
			{
				var imgarr=[];
				var box=cntbox;
				//console.log('cntbox=');
				//console.log(cntbox);
				var imgs=null;
				imgs=box.find('img');
				//console.log(imgs);
				for(var i=0;i<imgs.length;i++)
				{
					var n=imgs.eq(i).attr("name")||imgs.eq(i).attr("id");
					if(n!=null&&n!=undefined&&n.indexOf('imgview_')>=0)
					{
						var a={};
						a.src=imgs.eq(i).attr("src");
						a.width=null;
						imgarr.push(a);
					}
				}
				//console.log(imgarr);
				return imgarr;
			}

		}